From nobody Fri Nov 7 10:15:08 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548189577988927.6260455607371; Tue, 22 Jan 2019 12:39:37 -0800 (PST) Received: from localhost ([127.0.0.1]:49222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm2pc-0000oH-8l for importer@patchew.org; Tue, 22 Jan 2019 15:39:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm1nf-0007Uh-QN for qemu-devel@nongnu.org; Tue, 22 Jan 2019 14:33:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gm1gq-0005ex-2q for qemu-devel@nongnu.org; Tue, 22 Jan 2019 14:26:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55560) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gm1gp-0005W7-TN for qemu-devel@nongnu.org; Tue, 22 Jan 2019 14:26:28 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42EC258E3E for ; Tue, 22 Jan 2019 14:41:07 +0000 (UTC) Received: from dhcp201-121.englab.pnq.redhat.com (dhcp-10-65-161-12.pnq.redhat.com [10.65.161.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51AFE5C8A7; Tue, 22 Jan 2019 14:41:05 +0000 (UTC) From: Pankaj Gupta To: qemu-devel@nongnu.org Date: Tue, 22 Jan 2019 20:11:03 +0530 Message-Id: <20190122144103.18310-1-pagupta@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 22 Jan 2019 14:41:07 +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] 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: pagupta@redhat.com, marcandre.lureau@redhat.com, xiaohli@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Hotplugging existing char chardev with qmp, dereferences(removes)=20 existing chardev. This patch avoids adding a chardev if a chardev=20 with same id exists. RH BZ 1660831:=20 # (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=20 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 =20 Reported-by: Xiaohui Li Signed-off-by: Pankaj Gupta --- 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, Chardev= Backend *backend, ChardevReturn *ret; Chardev *chr; =20 + chr =3D qemu_chr_find(id); + if (chr) { + error_setg(errp, "Chardev '%s' already exist", id); + return NULL; + } + cc =3D char_get_class(ChardevBackendKind_str(backend->type), errp); if (!cc) { return NULL; --=20 2.14.3