From nobody Fri May 17 09:18:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632474306; cv=none; d=zohomail.com; s=zohoarc; b=EqqREihdjtR7shQkt+hqcDsJhW+ycGxdGszXg8bQw8Fry9gToGJ3pl0gPGtUtA1iMb3GSpLAud+ye82f5ZmpE92u2/xjB0A+2QEglWYNJOix+pqZ/jk2BIVsZNroj/EICd9HH/CQNeRM8mY7QAxA0SE/FiLnKKUWcjUXHWfU/Dc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632474306; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WVZZuZu4LsfvcVGJuILGBV61qwCzXv4Jk2+5G7mxNqM=; b=iah4PG27fTAGvt+j8Vmj4vjOGSjSP6r7ezl3IxtNf9+GAVaaCVXe29dcU0+72zQSgdWbx3x9w+ZnZVaS26fWz9DWoWbffenRwG7kgad01r/lZnlrLwJNnZHzGG+p5VXy858TKPAGP0vegWOc2/H9jrfimMZ/bUnEydILhQWYzBk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 163247430635639.00614515582856; Fri, 24 Sep 2021 02:05:06 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-261-fPqCwxtvM2aHt_glbnS3pA-1; Fri, 24 Sep 2021 05:05:04 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D22C11007905; Fri, 24 Sep 2021 09:04:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1622110013C1; Fri, 24 Sep 2021 09:04:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A0B984E58F; Fri, 24 Sep 2021 09:04:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18O94t1B023989 for ; Fri, 24 Sep 2021 05:04:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id E071C5E268; Fri, 24 Sep 2021 09:04:55 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id F06A55D9DD; Fri, 24 Sep 2021 09:04:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632474305; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=WVZZuZu4LsfvcVGJuILGBV61qwCzXv4Jk2+5G7mxNqM=; b=A2ffv5zalCF34WzHVJNxxsMCaV7s9oZXvN8ggoaU+MVeYZHFPsMEsmNrWNovLum5TdV49h 9KzKVRdw1N70VqhYGYf9oH4NCBgskAeSUbaRYFqV+Of0pxzFlwcZ9lRMMuW3e8MUpPgYKE T0huuxlaDoDX7XtGSMc/SmwmIpt/TH0= X-MC-Unique: fPqCwxtvM2aHt_glbnS3pA-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH 01/11] qom: Reduce use of error_propagate() Date: Fri, 24 Sep 2021 11:04:17 +0200 Message-Id: <20210924090427.9218-2-kwolf@redhat.com> In-Reply-To: <20210924090427.9218-1-kwolf@redhat.com> References: <20210924090427.9218-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, libvir-list@redhat.com, armbru@redhat.com, its@irrelevant.dk, pbonzini@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632474308777100001 Content-Type: text/plain; charset="utf-8" ERRP_GUARD() makes debugging easier by making sure that &error_abort still fails at the real origin of the error instead of error_propagate(). Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster --- qom/object.c | 7 +++---- qom/object_interfaces.c | 17 ++++++----------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/qom/object.c b/qom/object.c index e86cb05b84..6be710bc40 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1389,7 +1389,7 @@ bool object_property_get(Object *obj, const char *nam= e, Visitor *v, bool object_property_set(Object *obj, const char *name, Visitor *v, Error **errp) { - Error *err =3D NULL; + ERRP_GUARD(); ObjectProperty *prop =3D object_property_find_err(obj, name, errp); =20 if (prop =3D=3D NULL) { @@ -1400,9 +1400,8 @@ bool object_property_set(Object *obj, const char *nam= e, Visitor *v, error_setg(errp, QERR_PERMISSION_DENIED); return false; } - prop->set(obj, v, name, prop->opaque, &err); - error_propagate(errp, err); - return !err; + prop->set(obj, v, name, prop->opaque, errp); + return !*errp; } =20 bool object_property_set_str(Object *obj, const char *name, diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index ad9b56b59a..80691e88cd 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -45,26 +45,21 @@ bool user_creatable_can_be_deleted(UserCreatable *uc) static void object_set_properties_from_qdict(Object *obj, const QDict *qdi= ct, Visitor *v, Error **errp) { + ERRP_GUARD(); const QDictEntry *e; - Error *local_err =3D NULL; =20 - if (!visit_start_struct(v, NULL, NULL, 0, &local_err)) { - goto out; + if (!visit_start_struct(v, NULL, NULL, 0, errp)) { + return; } for (e =3D qdict_first(qdict); e; e =3D qdict_next(qdict, e)) { - if (!object_property_set(obj, e->key, v, &local_err)) { + if (!object_property_set(obj, e->key, v, errp)) { break; } } - if (!local_err) { - visit_check_struct(v, &local_err); + if (!*errp) { + visit_check_struct(v, errp); } visit_end_struct(v, NULL); - -out: - if (local_err) { - error_propagate(errp, local_err); - } } =20 void object_set_properties_from_keyval(Object *obj, const QDict *qdict, --=20 2.31.1 From nobody Fri May 17 09:18:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632474313; cv=none; d=zohomail.com; s=zohoarc; b=n+Umtojl6tgDcumx1i1raCr9UFl4h5YjrT4yKNHaje4ByTFYcUVWXalsGSlCIpZxkA5AK/xAVHph38Vg4wcHFxCmzqDcApXmrr7GP/lrO3AtBag6QVn+an/ExPO06gUc14hgN3+dKGKCo6d7f2atysLOX+ftG5WeGcxKqLMsy9w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632474313; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UsQ4v0z1HIL1RRBjmY+F/DST9tQdONVmLarwTyqDWXI=; b=I+pUA5RfANZIsSRSzyB3XZthDewXM/I8lQ5Q7xpRdDLGBFUSlqBXQrzeuLScap3re2X3GMoWDfWVwAlouvWRJ+SZiPDKyATZs3cO+cbAGf3UBaVAw67Dx/8+OStcThFhU2HgCcoes2CxrIVZ8xOAAIa8Dl3wX55nsQUs80Fu1Tk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 163247431355021.298434117593956; Fri, 24 Sep 2021 02:05:13 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-566-zEichfGmOiisQYdQGEQ0Ug-1; Fri, 24 Sep 2021 05:05:10 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B2198100790C; Fri, 24 Sep 2021 09:05:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 94246197FC; Fri, 24 Sep 2021 09:05:05 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5CBE01803B30; Fri, 24 Sep 2021 09:05:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18O9535b024026 for ; Fri, 24 Sep 2021 05:05:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id E5BC55DF2F; Fri, 24 Sep 2021 09:05:03 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3AD545D9DD; Fri, 24 Sep 2021 09:04:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632474312; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=UsQ4v0z1HIL1RRBjmY+F/DST9tQdONVmLarwTyqDWXI=; b=OUQvc/GUqRbNd94cDhfgqu+klUBubSkoCp4KOO+nrvnInDouH6khhLCyd56AkUP/XLKssf Tjc8Klbcw5xUulSiYSU5BZThRuSAhzYX8fukXgZd73bU9KKk4bvFJUqTGOsdR5POCBmPJo VXjYgvulv3wJw39QGr3E1xoljROfEOY= X-MC-Unique: zEichfGmOiisQYdQGEQ0Ug-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH 02/11] iotests/245: Fix type for iothread property Date: Fri, 24 Sep 2021 11:04:18 +0200 Message-Id: <20210924090427.9218-3-kwolf@redhat.com> In-Reply-To: <20210924090427.9218-1-kwolf@redhat.com> References: <20210924090427.9218-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, libvir-list@redhat.com, armbru@redhat.com, its@irrelevant.dk, pbonzini@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632474315916100001 Content-Type: text/plain; charset="utf-8" iothread is a string property, so None (=3D JSON null) is not a valid value for it. Pass the empty string instead to get the default iothread. Signed-off-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/245 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245 index bf8261eec0..9b12b42eed 100755 --- a/tests/qemu-iotests/245 +++ b/tests/qemu-iotests/245 @@ -1189,10 +1189,10 @@ class TestBlockdevReopen(iotests.QMPTestCase): self.run_test_iothreads('iothread0', 'iothread0') =20 def test_iothreads_switch_backing(self): - self.run_test_iothreads('iothread0', None) + self.run_test_iothreads('iothread0', '') =20 def test_iothreads_switch_overlay(self): - self.run_test_iothreads(None, 'iothread0') + self.run_test_iothreads('', 'iothread0') =20 if __name__ =3D=3D '__main__': iotests.activate_logging() --=20 2.31.1 From nobody Fri May 17 09:18:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632474549; cv=none; d=zohomail.com; s=zohoarc; b=jkHdmx4KPApLQMSAJQMMx8U68EsbXjbKRRqIIiFtK9OS2QlzJAckqQM20SRZqON2dRptjt9QwG7Mv9z6MGXHs2DRcFXfO6ODOB8MSRtpKRGQUkr/Ikh83E7SvkTjK/vtBAbWMeTZYoW4NcfEyp8DReAsbHTrMRZiACVlswyge0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632474549; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=s+MvauAKX8Sg5PD9bcfdZIejMYCjC+7abVclCzHOyBc=; b=oH/S2LjIRfbp+MgCRRgfVrx4DHeNuUlqeFyfxg5LjeT42CMiDwE77v5wUuT8g7gbSoOhwmREibj1alhqyx4aKZ26Fk+LoxGMKP5fCYcV6jUVhYzMZpiC8LK8RGY4hM5I5ElyalrgDV04eJMHZbxDksDDqlkDpTaNPO+KIS1c+p4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1632474549533862.0801853214838; Fri, 24 Sep 2021 02:09:09 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-280-9LsD7MfhMQ2GkQEyou-lBw-1; Fri, 24 Sep 2021 05:07:22 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 220341006AA3; Fri, 24 Sep 2021 09:07:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0758D652AF; Fri, 24 Sep 2021 09:07:18 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C7D481832DD7; Fri, 24 Sep 2021 09:07:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18O95kHK024153 for ; Fri, 24 Sep 2021 05:05:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 782A95E253; Fri, 24 Sep 2021 09:05:46 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39E695D9DC; Fri, 24 Sep 2021 09:05:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632474548; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=s+MvauAKX8Sg5PD9bcfdZIejMYCjC+7abVclCzHOyBc=; b=EBVlsi/6RWui+A7JyiEQXodMpaDobysXIFj45wsLrW5UoB3ElE1gFWg08hiSkysLtetZg2 rfxYQzV35T67DwdNKwar5GFUSNDz68L2CLyVZfaNMvykYUHo8GxM+N8M/wQuc584dC6yaF Vu7QgkUPVk8PxPxeqxoitwpESmZ7jM0= X-MC-Unique: 9LsD7MfhMQ2GkQEyou-lBw-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH 03/11] iotests/051: Fix typo Date: Fri, 24 Sep 2021 11:04:19 +0200 Message-Id: <20210924090427.9218-4-kwolf@redhat.com> In-Reply-To: <20210924090427.9218-1-kwolf@redhat.com> References: <20210924090427.9218-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, libvir-list@redhat.com, armbru@redhat.com, its@irrelevant.dk, pbonzini@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632474549867100001 Content-Type: text/plain; charset="utf-8" The iothread isn't called 'iothread0', but 'thread0'. Depending on the order that properties are parsed, the error message may change from the expected one to another one saying that the iothread doesn't exist. Signed-off-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/051 | 2 +- tests/qemu-iotests/051.pc.out | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/051 b/tests/qemu-iotests/051 index 7bf29343d7..1d2fa93a11 100755 --- a/tests/qemu-iotests/051 +++ b/tests/qemu-iotests/051 @@ -199,7 +199,7 @@ case "$QEMU_DEFAULT_MACHINE" in # virtio-blk enables the iothread only when the driver initialises= the # device, so a second virtio-blk device can't be added even with t= he # same iothread. virtio-scsi allows this. - run_qemu $iothread -device virtio-blk-pci,drive=3Ddisk,iothread=3D= iothread0,share-rw=3Don + run_qemu $iothread -device virtio-blk-pci,drive=3Ddisk,iothread=3D= thread0,share-rw=3Don run_qemu $iothread -device virtio-scsi,id=3Dvirtio-scsi1,iothread= =3Dthread0 -device scsi-hd,bus=3Dvirtio-scsi1.0,drive=3Ddisk,share-rw=3Don ;; *) diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out index afe7632964..063e4fc584 100644 --- a/tests/qemu-iotests/051.pc.out +++ b/tests/qemu-iotests/051.pc.out @@ -183,9 +183,9 @@ Testing: -drive file=3DTEST_DIR/t.qcow2,if=3Dnone,node-= name=3Ddisk -object iothread,id QEMU X.Y.Z monitor - type 'help' for more information (qemu) QEMU_PROG: -device scsi-hd,bus=3Dvirtio-scsi1.0,drive=3Ddisk,share-= rw=3Don: Cannot change iothread of active block backend =20 -Testing: -drive file=3DTEST_DIR/t.qcow2,if=3Dnone,node-name=3Ddisk -object= iothread,id=3Dthread0 -device virtio-scsi,iothread=3Dthread0,id=3Dvirtio-s= csi0 -device scsi-hd,bus=3Dvirtio-scsi0.0,drive=3Ddisk,share-rw=3Don -devic= e virtio-blk-pci,drive=3Ddisk,iothread=3Diothread0,share-rw=3Don +Testing: -drive file=3DTEST_DIR/t.qcow2,if=3Dnone,node-name=3Ddisk -object= iothread,id=3Dthread0 -device virtio-scsi,iothread=3Dthread0,id=3Dvirtio-s= csi0 -device scsi-hd,bus=3Dvirtio-scsi0.0,drive=3Ddisk,share-rw=3Don -devic= e virtio-blk-pci,drive=3Ddisk,iothread=3Dthread0,share-rw=3Don QEMU X.Y.Z monitor - type 'help' for more information -(qemu) QEMU_PROG: -device virtio-blk-pci,drive=3Ddisk,iothread=3Diothread0= ,share-rw=3Don: Cannot change iothread of active block backend +(qemu) QEMU_PROG: -device virtio-blk-pci,drive=3Ddisk,iothread=3Dthread0,s= hare-rw=3Don: Cannot change iothread of active block backend =20 Testing: -drive file=3DTEST_DIR/t.qcow2,if=3Dnone,node-name=3Ddisk -object= iothread,id=3Dthread0 -device virtio-scsi,iothread=3Dthread0,id=3Dvirtio-s= csi0 -device scsi-hd,bus=3Dvirtio-scsi0.0,drive=3Ddisk,share-rw=3Don -devic= e virtio-scsi,id=3Dvirtio-scsi1,iothread=3Dthread0 -device scsi-hd,bus=3Dvi= rtio-scsi1.0,drive=3Ddisk,share-rw=3Don QEMU X.Y.Z monitor - type 'help' for more information --=20 2.31.1 From nobody Fri May 17 09:18:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632474448; cv=none; d=zohomail.com; s=zohoarc; b=ZURr/yi7g0CjdkB9yjOveqpiJ8tjyW2OP3EKeY5I1Yrvrs2jZPquUJgqk1P47+SbQITO0CargQdn9AECS0/pEg3jGb+9gXgKeRk1P1vCtD/mQ9Qq2Jb8Ac92UiOJ8WOcQ3K22DIo/pqWp7uUysj4t7CX0fB+vJW26ia8DejsKBg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632474448; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2MMbngAgfFJdLFjKN1OY+WDHDson9Zzsfp6RdzHlTdk=; b=HYVj9vA5ifVCor1/3IxTOdnO9SqUeYs9boFEYKzRmB07RFhi8DzX0nsHFoqyvmdRA/3gmlhINp24Wblaq70OMZheZ3dwF8EcvMBozQh8Nr7YuPtGk8eZE362c58Qn4RqfcGvV1ZoF0iRsLYMDe+pl3oBec/LnYrQPVmdZjgZDq8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1632474448189435.710943434108; Fri, 24 Sep 2021 02:07:28 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-277-7zOnuXMoOa2TaZsnTBe59w-1; Fri, 24 Sep 2021 05:07:25 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B92661007905; Fri, 24 Sep 2021 09:07:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A4915FC25; Fri, 24 Sep 2021 09:07:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6A3A31832DDA; Fri, 24 Sep 2021 09:07:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18O95uN9024168 for ; Fri, 24 Sep 2021 05:05:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id A23505DEB8; Fri, 24 Sep 2021 09:05:56 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0C265D9DC; Fri, 24 Sep 2021 09:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632474447; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=2MMbngAgfFJdLFjKN1OY+WDHDson9Zzsfp6RdzHlTdk=; b=Og/HRpts4W3G5kQxtUSVsdPE2wp7UGCTDGS9PLhpkincEwq5w3vCJ1U0x5A4ndOzyYSKj9 t/ErnJbTXZprZ0w7ypSyDPx3An1OrLvEK3Eq9sLGqLSzcT2Q2i2bAfmot9prLE9MGGVSgX kyt1WGdJ4/LZTAH6Uy5bB1/ZNqaoN+s= X-MC-Unique: 7zOnuXMoOa2TaZsnTBe59w-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH 04/11] qdev: Avoid using string visitor for properties Date: Fri, 24 Sep 2021 11:04:20 +0200 Message-Id: <20210924090427.9218-5-kwolf@redhat.com> In-Reply-To: <20210924090427.9218-1-kwolf@redhat.com> References: <20210924090427.9218-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, libvir-list@redhat.com, armbru@redhat.com, its@irrelevant.dk, pbonzini@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632474448539100001 Content-Type: text/plain; charset="utf-8" The only thing the string visitor adds compared to a keyval visitor is list support. git grep for 'visit_start_list' and 'visit.*List' shows that devices don't make use of this. In a world with a QAPIfied command line interface, the keyval visitor is used to parse the command line. In order to make sure that no devices start using this feature that would make backwards compatibility harder, just switch away from object_property_parse(), which internally uses the string visitor, to a keyval visitor and object_property_set(). Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- softmmu/qdev-monitor.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 0705f00846..034b999401 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -28,6 +28,8 @@ #include "qapi/qmp/dispatch.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" +#include "qapi/qmp/qstring.h" +#include "qapi/qobject-input-visitor.h" #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qemu/help_option.h" @@ -198,16 +200,28 @@ static int set_property(void *opaque, const char *nam= e, const char *value, Error **errp) { Object *obj =3D opaque; + QString *val; + Visitor *v; + int ret; =20 if (strcmp(name, "driver") =3D=3D 0) return 0; if (strcmp(name, "bus") =3D=3D 0) return 0; =20 - if (!object_property_parse(obj, name, value, errp)) { - return -1; + val =3D qstring_from_str(value); + v =3D qobject_input_visitor_new_keyval(QOBJECT(val)); + + if (!object_property_set(obj, name, v, errp)) { + ret =3D -1; + goto out; } - return 0; + + ret =3D 0; +out: + visit_free(v); + qobject_unref(val); + return ret; } =20 static const char *find_typename_by_alias(const char *alias) --=20 2.31.1 From nobody Fri May 17 09:18:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632474450; cv=none; d=zohomail.com; s=zohoarc; b=QyKNLA20NPTt4MaUI/i0PSU7kh0ATgMSIKGW52Fk99+IZIxKZII9MR2dXZ06KIqRbToACLYdxGNF4FyxeOKUntcXbKslN8U599qk7s73PMuqcxAUEnnQyjjCDqdd8t9p+05Awngs/+cnn1h0MZvAHYq4wf7BV7MR+SR67caOOko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632474450; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KzPpKcm05vMxAm5x56Ljr93Ez4xNOIelk3Z0Gs8Yf1w=; b=oBc/DAQkkKf80B2IixJEzYkDXYc5ljiTksCAogsijQOUjChszqiFNdm/GuYZc+OEoHk6jOZ29j3iSAoLPlesR9EKk9Xy3arPMNfrDIKXx2ssKhqqxYhrSfy+j5uq/NIPKily6V0SqtgZ2wYMqO8UsOxwtgfzsh/rU9Vy0XLB66s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1632474450537359.1166718363371; Fri, 24 Sep 2021 02:07:30 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-400-MktYFtuwPmO8bI_2IgznOg-1; Fri, 24 Sep 2021 05:07:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 284F150750; Fri, 24 Sep 2021 09:07:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0BBA66A905; Fri, 24 Sep 2021 09:07:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CFDC34EA38; Fri, 24 Sep 2021 09:07:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18O95weZ024180 for ; Fri, 24 Sep 2021 05:05:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id C8CBD5E253; Fri, 24 Sep 2021 09:05:58 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAF895D9DC; Fri, 24 Sep 2021 09:05:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632474449; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=KzPpKcm05vMxAm5x56Ljr93Ez4xNOIelk3Z0Gs8Yf1w=; b=dZdHnLjPMVuUyQbApm/TF9TkpfEMUYgcJEM+OHPRuT5qCcNPL+J/1/9MZEyShr9Fx7brN2 eBEfsqnVt4lIZoYKKClIEq5i39CzjW2vagSr4DsYVlE2TY3/ecME/xYEy7+nysu88i/DFZ QXFaBa+XY2KiIgkvAaWpjcmu6OFkj78= X-MC-Unique: MktYFtuwPmO8bI_2IgznOg-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH 05/11] qdev: Make DeviceState.id independent of QemuOpts Date: Fri, 24 Sep 2021 11:04:21 +0200 Message-Id: <20210924090427.9218-6-kwolf@redhat.com> In-Reply-To: <20210924090427.9218-1-kwolf@redhat.com> References: <20210924090427.9218-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, libvir-list@redhat.com, armbru@redhat.com, its@irrelevant.dk, pbonzini@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632474452655100001 Content-Type: text/plain; charset="utf-8" DeviceState.id is a pointer to a string that is stored in the QemuOpts object DeviceState.opts and freed together with it. We want to create devices without going through QemuOpts in the future, so make this a separately allocated string. Signed-off-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/hw/qdev-core.h | 2 +- include/monitor/qdev.h | 2 +- hw/arm/virt.c | 2 +- hw/core/qdev.c | 1 + hw/pci-bridge/pci_expander_bridge.c | 2 +- hw/ppc/e500.c | 2 +- softmmu/qdev-monitor.c | 5 +++-- 7 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 34c8a7506a..1857d9698e 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -176,7 +176,7 @@ struct DeviceState { Object parent_obj; /*< public >*/ =20 - const char *id; + char *id; char *canonical_path; bool realized; bool pending_deleted_event; diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index eaa947d73a..389287eb44 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -9,6 +9,6 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error= **errp); =20 int qdev_device_help(QemuOpts *opts); DeviceState *qdev_device_add(QemuOpts *opts, Error **errp); -void qdev_set_id(DeviceState *dev, const char *id); +void qdev_set_id(DeviceState *dev, char *id); =20 #endif diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 1d59f0e59f..f933d48d3b 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1459,7 +1459,7 @@ static void create_platform_bus(VirtMachineState *vms) MemoryRegion *sysmem =3D get_system_memory(); =20 dev =3D qdev_new(TYPE_PLATFORM_BUS_DEVICE); - dev->id =3D TYPE_PLATFORM_BUS_DEVICE; + dev->id =3D g_strdup(TYPE_PLATFORM_BUS_DEVICE); qdev_prop_set_uint32(dev, "num_irqs", PLATFORM_BUS_NUM_IRQS); qdev_prop_set_uint32(dev, "mmio_size", vms->memmap[VIRT_PLATFORM_BUS].= size); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); diff --git a/hw/core/qdev.c b/hw/core/qdev.c index cefc5eaa0a..d918b50a1d 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -956,6 +956,7 @@ static void device_finalize(Object *obj) } =20 qemu_opts_del(dev->opts); + g_free(dev->id); } =20 static void device_class_base_init(ObjectClass *class, void *data) diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expand= er_bridge.c index 7112dc3062..10e6e7c2ab 100644 --- a/hw/pci-bridge/pci_expander_bridge.c +++ b/hw/pci-bridge/pci_expander_bridge.c @@ -245,7 +245,7 @@ static void pxb_dev_realize_common(PCIDevice *dev, bool= pcie, Error **errp) } else { bus =3D pci_root_bus_new(ds, "pxb-internal", NULL, NULL, 0, TYPE_P= XB_BUS); bds =3D qdev_new("pci-bridge"); - bds->id =3D dev_name; + bds->id =3D g_strdup(dev_name); qdev_prop_set_uint8(bds, PCI_BRIDGE_DEV_PROP_CHASSIS_NR, pxb->bus_= nr); qdev_prop_set_bit(bds, PCI_BRIDGE_DEV_PROP_SHPC, false); } diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c index 95451414dd..960e7efcd3 100644 --- a/hw/ppc/e500.c +++ b/hw/ppc/e500.c @@ -1006,7 +1006,7 @@ void ppce500_init(MachineState *machine) /* Platform Bus Device */ if (pmc->has_platform_bus) { dev =3D qdev_new(TYPE_PLATFORM_BUS_DEVICE); - dev->id =3D TYPE_PLATFORM_BUS_DEVICE; + dev->id =3D g_strdup(TYPE_PLATFORM_BUS_DEVICE); qdev_prop_set_uint32(dev, "num_irqs", pmc->platform_bus_num_irqs); qdev_prop_set_uint32(dev, "mmio_size", pmc->platform_bus_size); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 034b999401..1207e57a46 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -592,7 +592,8 @@ static BusState *qbus_find(const char *path, Error **er= rp) return bus; } =20 -void qdev_set_id(DeviceState *dev, const char *id) +/* Takes ownership of @id, will be freed when deleting the device */ +void qdev_set_id(DeviceState *dev, char *id) { if (id) { dev->id =3D id; @@ -690,7 +691,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **er= rp) } } =20 - qdev_set_id(dev, qemu_opts_id(opts)); + qdev_set_id(dev, g_strdup(qemu_opts_id(opts))); =20 /* set properties */ if (qemu_opt_foreach(opts, set_property, dev, errp)) { --=20 2.31.1 From nobody Fri May 17 09:18:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632474454; cv=none; d=zohomail.com; s=zohoarc; b=RHu/PiJGXa3b7K2JXS86HDOBwiH2gOzHT9nNH66vTlZbdlevVzUMzk3U32ZtihzJbck6uoGjOzv84bRAQXKhidzjjY5Vpny8/W3n7+UgHYJQQ5IHk6FbDg4tQFmRHjk8iLMcKwFvOI38Emls3LtkpYavbgnRFsGL0jXqlKLCHv0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632474454; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PLOXu1775eDMROuvd0cnsapq2Z/Q6amD0L48n6m4Sdo=; b=epG+YQWpiQ/rcEHJvxJ9kupiEPxRBvfT4odD4s6yBwPnVDkHxp908s68MNxSbE/FjBwPNjSV3AtZcVprNJSdBK6/NhK5qWUXtCcvplLwCnKmqDfC9duHTL3EX1ekzJP2RiqY+d0UgfgYXr0oZ0dGc4ykRWEeyYPadgg3xoa3a2w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1632474454420936.1755763241393; Fri, 24 Sep 2021 02:07:34 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-5-brziOt9pNAeF8e7rCzcQXw-1; Fri, 24 Sep 2021 05:07:31 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 417A350753; Fri, 24 Sep 2021 09:07:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 224A85DA61; Fri, 24 Sep 2021 09:07:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E1A5C4EA3B; Fri, 24 Sep 2021 09:07:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18O96M3b024226 for ; Fri, 24 Sep 2021 05:06:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5CF0417B4F; Fri, 24 Sep 2021 09:06:22 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C8E75D9DC; Fri, 24 Sep 2021 09:05:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632474453; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=PLOXu1775eDMROuvd0cnsapq2Z/Q6amD0L48n6m4Sdo=; b=UayrYvaGV4lS+eVDNW/A1uMeeuNk1lc0K4VQKmg7/iGlcMMsu7HK1fxEoehVMYSJjWiX/d Sm7WvMAOpZ3pHi+epEJVZWUkvbBD6mYH6ArKtnNdJycbhvU6bOacbsRHBdsi/gH1anFXwe zzzFa5QRlgNJyRkru7rb5L0iMxjiFRw= X-MC-Unique: brziOt9pNAeF8e7rCzcQXw-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH 06/11] qdev: Add Error parameter to qdev_set_id() Date: Fri, 24 Sep 2021 11:04:22 +0200 Message-Id: <20210924090427.9218-7-kwolf@redhat.com> In-Reply-To: <20210924090427.9218-1-kwolf@redhat.com> References: <20210924090427.9218-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, libvir-list@redhat.com, armbru@redhat.com, its@irrelevant.dk, pbonzini@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632474455065100001 Content-Type: text/plain; charset="utf-8" object_property_add_child() fails (with &error_abort) if an object with the same name already exists. As long as QemuOpts is in use for -device and device_add, it catches duplicate IDs before qdev_set_id() is even called. However, for enabling non-QemuOpts code paths, we need to make sure that the condition doesn't cause a crash, but fails gracefully. Signed-off-by: Kevin Wolf --- include/monitor/qdev.h | 2 +- hw/xen/xen-legacy-backend.c | 3 ++- softmmu/qdev-monitor.c | 16 ++++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index 389287eb44..7961308c75 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -9,6 +9,6 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error= **errp); =20 int qdev_device_help(QemuOpts *opts); DeviceState *qdev_device_add(QemuOpts *opts, Error **errp); -void qdev_set_id(DeviceState *dev, char *id); +void qdev_set_id(DeviceState *dev, char *id, Error **errp); =20 #endif diff --git a/hw/xen/xen-legacy-backend.c b/hw/xen/xen-legacy-backend.c index dd8ae1452d..17aca85ddc 100644 --- a/hw/xen/xen-legacy-backend.c +++ b/hw/xen/xen-legacy-backend.c @@ -276,7 +276,8 @@ static struct XenLegacyDevice *xen_be_get_xendev(const = char *type, int dom, xendev =3D g_malloc0(ops->size); object_initialize(&xendev->qdev, ops->size, TYPE_XENBACKEND); OBJECT(xendev)->free =3D g_free; - qdev_set_id(DEVICE(xendev), g_strdup_printf("xen-%s-%d", type, dev)); + qdev_set_id(DEVICE(xendev), g_strdup_printf("xen-%s-%d", type, dev), + &error_abort); qdev_realize(DEVICE(xendev), xen_sysbus, &error_fatal); object_unref(OBJECT(xendev)); =20 diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 1207e57a46..c2af906df0 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -593,26 +593,27 @@ static BusState *qbus_find(const char *path, Error **= errp) } =20 /* Takes ownership of @id, will be freed when deleting the device */ -void qdev_set_id(DeviceState *dev, char *id) +void qdev_set_id(DeviceState *dev, char *id, Error **errp) { if (id) { dev->id =3D id; } =20 if (dev->id) { - object_property_add_child(qdev_get_peripheral(), dev->id, - OBJECT(dev)); + object_property_try_add_child(qdev_get_peripheral(), dev->id, + OBJECT(dev), errp); } else { static int anon_count; gchar *name =3D g_strdup_printf("device[%d]", anon_count++); - object_property_add_child(qdev_get_peripheral_anon(), name, - OBJECT(dev)); + object_property_try_add_child(qdev_get_peripheral_anon(), name, + OBJECT(dev), errp); g_free(name); } } =20 DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) { + ERRP_GUARD(); DeviceClass *dc; const char *driver, *path; DeviceState *dev =3D NULL; @@ -691,7 +692,10 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **e= rrp) } } =20 - qdev_set_id(dev, g_strdup(qemu_opts_id(opts))); + qdev_set_id(dev, g_strdup(qemu_opts_id(opts)), errp); + if (*errp) { + goto err_del_dev; + } =20 /* set properties */ if (qemu_opt_foreach(opts, set_property, dev, errp)) { --=20 2.31.1 From nobody Fri May 17 09:18:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632474406; cv=none; d=zohomail.com; s=zohoarc; b=B5O2yin4Lo4BUJe7rX+qHbw2r48QAQs7TM4ZkF7PU2PD/bLSZbGy7k7qeMw8S4Vo+7As4u1/RgNhdJ4ErsAD5XvI6YHE2dNuG8HhsZPcEllnfzJQR9XN+co0McqwN8HNZwxSbQQ8BkivNuatKmeKf/B+fo2Zipx8KpUxdGbtX1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632474406; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FVk/66SMV9Z14GpKnbeJNn6b61WCANcun218vXI9kbI=; b=WviPWuSQsRzL4MbvQar1oyg4C8zuR0WNdc5T3e/kEWtNhHDY6HzqXEdHTtIvBYagI//oOJapVY2dmYeoyGH3AQLrXDEwNZD587PjTWDLztiT41l/wvDwkBYc17w5S/AvRi6SgJ7EErwIr755NSgiD57eFxGFzI4r9mYGK4JQqAU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1632474406641390.8188543413029; Fri, 24 Sep 2021 02:06:46 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-131-89Orecw5ODSz9YZ0KHvUEw-1; Fri, 24 Sep 2021 05:06:30 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6B74802CB3; Fri, 24 Sep 2021 09:06:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9AA4D60936; Fri, 24 Sep 2021 09:06:25 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6C6861806D00; Fri, 24 Sep 2021 09:06:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18O96OnQ024236 for ; Fri, 24 Sep 2021 05:06:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 82CCB5E253; Fri, 24 Sep 2021 09:06:24 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id A534D5D9DC; Fri, 24 Sep 2021 09:06:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632474405; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FVk/66SMV9Z14GpKnbeJNn6b61WCANcun218vXI9kbI=; b=Em3UPVOBhQzi4uWR4A1iAV+izmUHwY6mH4mYkZkc4DP85qUGYSTXeBTmyg4Scz7mn0Ffw+ r7642iRqoFTuX4DAQ3hXeycKvn5QoikhwkxSjBjQAFtWYeBYfQep4Z8GkvXQJJXwDHpIa/ erWEqBlcy+YBBDR4LBMM0Ntpu8i19cU= X-MC-Unique: 89Orecw5ODSz9YZ0KHvUEw-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH 07/11] qemu-option: Allow deleting opts during qemu_opts_foreach() Date: Fri, 24 Sep 2021 11:04:23 +0200 Message-Id: <20210924090427.9218-8-kwolf@redhat.com> In-Reply-To: <20210924090427.9218-1-kwolf@redhat.com> References: <20210924090427.9218-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, libvir-list@redhat.com, armbru@redhat.com, its@irrelevant.dk, pbonzini@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632474408807100001 Content-Type: text/plain; charset="utf-8" Use QTAILQ_FOREACH_SAFE() so that the current QemuOpts can be deleted while iterating through the whole list. Signed-off-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- util/qemu-option.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/qemu-option.c b/util/qemu-option.c index 61cb4a97bd..eedd08929b 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -1126,11 +1126,11 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts= _loopfunc func, void *opaque, Error **errp) { Location loc; - QemuOpts *opts; + QemuOpts *opts, *next; int rc =3D 0; =20 loc_push_none(&loc); - QTAILQ_FOREACH(opts, &list->head, next) { + QTAILQ_FOREACH_SAFE(opts, &list->head, next, next) { loc_restore(&opts->loc); rc =3D func(opaque, opts, errp); if (rc) { --=20 2.31.1 From nobody Fri May 17 09:18:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632474395; cv=none; d=zohomail.com; s=zohoarc; b=De1ZW6tlQ86XEUeAICDkFYv58YLBuTeBY4CCyo6Bw09+1loOsO5a3Qyvrm2fnKSfkKB9i5qvrYqgmSrE9lI5YcyaKjrbbFZF+H0XaXJCxwBDgQFKE/X5MTuJGLdt+7pxp/Qz/Z94HCL1dk2bvzRYj7S9ZEVJxnkq8O1X37fFlf4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632474395; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NlrxbgmS+/TVHjcAS9fhHQjT4bHTQkD3WH455XSSX5Y=; b=fVWCRsYY0hq0rT5PiAVh+iT7nIJuiwMfbDQSOBUIvAJlUsp1cf+Dk3AQ0yvcCTNYsSLn3DheLqfvONo1MoalhoDuyiluxIJPZweUKnEi4PIa7kqMPrBeikl049hX8sVreMGFwT1i1P2b9eK4F1OKiP1fcn1IJY8Z0lwiQo8VVqA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1632474395840164.66378130042403; Fri, 24 Sep 2021 02:06:35 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-185-wu_yCFuxM0-2hlXDOkFn4Q-1; Fri, 24 Sep 2021 05:06:33 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 608ED84A5F6; Fri, 24 Sep 2021 09:06:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3FEB576606; Fri, 24 Sep 2021 09:06:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 04F751806D02; Fri, 24 Sep 2021 09:06:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18O96QnY024259 for ; Fri, 24 Sep 2021 05:06:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id A79D518A69; Fri, 24 Sep 2021 09:06:26 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBED75D9DC; Fri, 24 Sep 2021 09:06:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632474394; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NlrxbgmS+/TVHjcAS9fhHQjT4bHTQkD3WH455XSSX5Y=; b=YiWotNSqEF65OuaQ5Y5B1nLYjVhfOluNHEGASW0K1SWbrWaOA8b8khYrzsSpIrkdpRVTBC CcUom2Q/djmyj7vVKmyCJD8Vj1y1fO5bjgBrRG27qLpT9WkHa8v3VCginnaF6MkfW3ym3Q eRiTL+NFj888vFI3RVVwOGrrO6/IhsE= X-MC-Unique: wu_yCFuxM0-2hlXDOkFn4Q-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH 08/11] qdev: Base object creation on QDict rather than QemuOpts Date: Fri, 24 Sep 2021 11:04:24 +0200 Message-Id: <20210924090427.9218-9-kwolf@redhat.com> In-Reply-To: <20210924090427.9218-1-kwolf@redhat.com> References: <20210924090427.9218-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, libvir-list@redhat.com, armbru@redhat.com, its@irrelevant.dk, pbonzini@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632474398078100001 Content-Type: text/plain; charset="utf-8" QDicts are both what QMP natively uses and what the keyval parser produces. Going through QemuOpts isn't useful for either one, so switch the main device creation function to QDicts. By sharing more code with the -object/object-add code path, we can even reduce the code size a bit. This commit doesn't remove the detour through QemuOpts from any code path yet, but it allows the following commits to do so. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/hw/qdev-core.h | 8 ++--- hw/core/qdev.c | 5 ++-- hw/net/virtio-net.c | 4 +-- hw/vfio/pci.c | 4 +-- softmmu/qdev-monitor.c | 67 +++++++++++++++++++----------------------- 5 files changed, 41 insertions(+), 47 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 1857d9698e..5b3d4704a5 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -180,7 +180,7 @@ struct DeviceState { char *canonical_path; bool realized; bool pending_deleted_event; - QemuOpts *opts; + QDict *opts; int hotplugged; bool allow_unplug_during_migration; BusState *parent_bus; @@ -202,7 +202,7 @@ struct DeviceListener { * hide a failover device depending for example on the device * opts. */ - bool (*hide_device)(DeviceListener *listener, QemuOpts *device_opts); + bool (*hide_device)(DeviceListener *listener, const QDict *device_opts= ); QTAILQ_ENTRY(DeviceListener) link; }; =20 @@ -831,13 +831,13 @@ void device_listener_unregister(DeviceListener *liste= ner); =20 /** * @qdev_should_hide_device: - * @opts: QemuOpts as passed on cmdline. + * @opts: options QDict * * Check if a device should be added. * When a device is added via qdev_device_add() this will be called, * and return if the device should be added now or not. */ -bool qdev_should_hide_device(QemuOpts *opts); +bool qdev_should_hide_device(const QDict *opts); =20 typedef enum MachineInitPhase { /* current_machine is NULL. */ diff --git a/hw/core/qdev.c b/hw/core/qdev.c index d918b50a1d..5b889866c5 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -28,6 +28,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qapi/qapi-events-qdev.h" +#include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qapi/visitor.h" #include "qemu/error-report.h" @@ -211,7 +212,7 @@ void device_listener_unregister(DeviceListener *listene= r) QTAILQ_REMOVE(&device_listeners, listener, link); } =20 -bool qdev_should_hide_device(QemuOpts *opts) +bool qdev_should_hide_device(const QDict *opts) { DeviceListener *listener; =20 @@ -955,7 +956,7 @@ static void device_finalize(Object *obj) dev->canonical_path =3D NULL; } =20 - qemu_opts_del(dev->opts); + qobject_unref(dev->opts); g_free(dev->id); } =20 diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index f205331dcf..5684c2b2b7 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3304,7 +3304,7 @@ static void virtio_net_migration_state_notifier(Notif= ier *notifier, void *data) } =20 static bool failover_hide_primary_device(DeviceListener *listener, - QemuOpts *device_opts) + const QDict *device_opts) { VirtIONet *n =3D container_of(listener, VirtIONet, primary_listener); const char *standby_id; @@ -3312,7 +3312,7 @@ static bool failover_hide_primary_device(DeviceListen= er *listener, if (!device_opts) { return false; } - standby_id =3D qemu_opt_get(device_opts, "failover_pair_id"); + standby_id =3D qdict_get_try_str(device_opts, "failover_pair_id"); if (g_strcmp0(standby_id, n->netclient_name) !=3D 0) { return false; } diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 4feaa1cb68..5cdf1d4298 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -29,10 +29,10 @@ #include "hw/qdev-properties.h" #include "hw/qdev-properties-system.h" #include "migration/vmstate.h" +#include "qapi/qmp/qdict.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/module.h" -#include "qemu/option.h" #include "qemu/range.h" #include "qemu/units.h" #include "sysemu/kvm.h" @@ -941,7 +941,7 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev) } =20 if (vfio_opt_rom_in_denylist(vdev)) { - if (dev->opts && qemu_opt_get(dev->opts, "rombar")) { + if (dev->opts && qdict_haskey(dev->opts, "rombar")) { warn_report("Device at %s is known to cause system instability" " issues during option rom execution", vdev->vbasedev.name); diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index c2af906df0..c09b7430eb 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -196,34 +196,6 @@ static void qdev_print_devinfos(bool show_no_user) g_slist_free(list); } =20 -static int set_property(void *opaque, const char *name, const char *value, - Error **errp) -{ - Object *obj =3D opaque; - QString *val; - Visitor *v; - int ret; - - if (strcmp(name, "driver") =3D=3D 0) - return 0; - if (strcmp(name, "bus") =3D=3D 0) - return 0; - - val =3D qstring_from_str(value); - v =3D qobject_input_visitor_new_keyval(QOBJECT(val)); - - if (!object_property_set(obj, name, v, errp)) { - ret =3D -1; - goto out; - } - - ret =3D 0; -out: - visit_free(v); - qobject_unref(val); - return ret; -} - static const char *find_typename_by_alias(const char *alias) { int i; @@ -611,15 +583,17 @@ void qdev_set_id(DeviceState *dev, char *id, Error **= errp) } } =20 -DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) +static DeviceState *qdev_device_add_from_qdict(const QDict *opts, + bool from_json, Error **err= p) { ERRP_GUARD(); DeviceClass *dc; const char *driver, *path; + char *id; DeviceState *dev =3D NULL; BusState *bus =3D NULL; =20 - driver =3D qemu_opt_get(opts, "driver"); + driver =3D qdict_get_try_str(opts, "driver"); if (!driver) { error_setg(errp, QERR_MISSING_PARAMETER, "driver"); return NULL; @@ -632,7 +606,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **er= rp) } =20 /* find bus */ - path =3D qemu_opt_get(opts, "bus"); + path =3D qdict_get_try_str(opts, "bus"); if (path !=3D NULL) { bus =3D qbus_find(path, errp); if (!bus) { @@ -652,8 +626,8 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **er= rp) } } =20 - if (qemu_opt_get(opts, "failover_pair_id")) { - if (!opts->id) { + if (qdict_haskey(opts, "failover_pair_id")) { + if (!qdict_haskey(opts, "id")) { error_setg(errp, "Device with failover_pair_id don't have id"); return NULL; } @@ -692,19 +666,25 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **= errp) } } =20 - qdev_set_id(dev, g_strdup(qemu_opts_id(opts)), errp); + id =3D g_strdup(qdict_get_try_str(opts, "id")); + qdev_set_id(dev, id, errp); if (*errp) { goto err_del_dev; } =20 /* set properties */ - if (qemu_opt_foreach(opts, set_property, dev, errp)) { + dev->opts =3D qdict_clone_shallow(opts); + qdict_del(dev->opts, "driver"); + qdict_del(dev->opts, "bus"); + qdict_del(dev->opts, "id"); + + object_set_properties_from_keyval(&dev->parent_obj, dev->opts, from_js= on, + errp); + if (*errp) { goto err_del_dev; } =20 - dev->opts =3D opts; if (!qdev_realize(DEVICE(dev), bus, errp)) { - dev->opts =3D NULL; goto err_del_dev; } return dev; @@ -717,6 +697,19 @@ err_del_dev: return NULL; } =20 +/* Takes ownership of @opts on success */ +DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) +{ + QDict *qdict =3D qemu_opts_to_qdict(opts, NULL); + DeviceState *ret; + + ret =3D qdev_device_add_from_qdict(qdict, false, errp); + if (ret) { + qemu_opts_del(opts); + } + qobject_unref(qdict); + return ret; +} =20 #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", #= # __VA_ARGS__) static void qbus_print(Monitor *mon, BusState *bus, int indent); --=20 2.31.1 From nobody Fri May 17 09:18:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632474486; cv=none; d=zohomail.com; s=zohoarc; b=NOyHhJLC7RTIJNdF7maq66lmeF99kdMJkc6iq2RUImRHH/ZBKe3xCDbWDNgsyeN50nXyqZv35gpAwcOyiDlNyiI5xzxOjV8NCIyjTzQFcYuIOvXdRoEXnyimzHJiLDPcsl5O51cJjW7W4vVBGHZW+jUojOyUigabpSC4o4OY5+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632474486; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qV5UEIxZEELZVQ6L7lFBojqVKwPn7e3y0+5jPMqL01U=; b=XkcY2XSADncHq0qnJK008tKOhzYGK2S7bo9LNbLZQ5IyxyzSajLq6LmIrHlxWlJQsHToX0OrjWzSt9ISnq4R2Ujw5ZQvHvGtstLbCMHJ70WUWIvcQ7vw9cXjYfKWgtUzKCpIMwi9hKQrM2wDD34KydfoBxp2P4ljs+wdW4lCV8U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1632474486827565.2667618378672; Fri, 24 Sep 2021 02:08:06 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-94-Eq3pxl5zOr2mpStU4spBug-1; Fri, 24 Sep 2021 05:06:52 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 602978064A5; Fri, 24 Sep 2021 09:06:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 42577102AE42; Fri, 24 Sep 2021 09:06:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 02FDF1806D02; Fri, 24 Sep 2021 09:06:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18O96j8E024320 for ; Fri, 24 Sep 2021 05:06:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id C07555E267; Fri, 24 Sep 2021 09:06:45 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id F00635D9DC; Fri, 24 Sep 2021 09:06:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632474485; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=qV5UEIxZEELZVQ6L7lFBojqVKwPn7e3y0+5jPMqL01U=; b=HmdQHH+4pYofostS7U8KjtUVN+w5LTL4O809MzITPhzuZsNOOXimGOADlPSXBzvadJ55le ThdTH9IzV/IsKMpYs1tJptSkyb8o/us0pEBmV+2/DfE6LNKGzgEiCuYPmSaiihVDxMwzyY NbIserreyuTNX4edIkQR9w8MqbO41os= X-MC-Unique: Eq3pxl5zOr2mpStU4spBug-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH 09/11] qdev: Avoid QemuOpts in QMP device_add Date: Fri, 24 Sep 2021 11:04:25 +0200 Message-Id: <20210924090427.9218-10-kwolf@redhat.com> In-Reply-To: <20210924090427.9218-1-kwolf@redhat.com> References: <20210924090427.9218-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, libvir-list@redhat.com, armbru@redhat.com, its@irrelevant.dk, pbonzini@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632474489628100003 Content-Type: text/plain; charset="utf-8" Directly call qdev_device_add_from_qdict() for QMP device_add instead of first going through QemuOpts and converting back to QDict. Note that this changes the behaviour of device_add, though in ways that should be considered bug fixes: QemuOpts ignores differences between data types, so you could successfully pass a string "123" for an integer property, or a string "on" for a boolean property (and vice versa). After this change, the correct data type for the property must be used in the JSON input. qemu_opts_from_qdict() also silently ignores any options whose value is a QDict, QList or QNull. To illustrate, the following QMP command was accepted before and is now rejected for both reasons: { "execute": "device_add", "arguments": { "driver": "scsi-cd", "drive": { "completely": "invalid" }, "physical_block_size": "4096" } } Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- softmmu/qdev-monitor.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index c09b7430eb..8622ccade6 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -812,7 +812,8 @@ void hmp_info_qdm(Monitor *mon, const QDict *qdict) qdev_print_devinfos(true); } =20 -void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp) +static void monitor_device_add(QDict *qdict, QObject **ret_data, + bool from_json, Error **errp) { QemuOpts *opts; DeviceState *dev; @@ -825,7 +826,9 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, E= rror **errp) qemu_opts_del(opts); return; } - dev =3D qdev_device_add(opts, errp); + qemu_opts_del(opts); + + dev =3D qdev_device_add_from_qdict(qdict, from_json, errp); =20 /* * Drain all pending RCU callbacks. This is done because @@ -838,13 +841,14 @@ void qmp_device_add(QDict *qdict, QObject **ret_data,= Error **errp) */ drain_call_rcu(); =20 - if (!dev) { - qemu_opts_del(opts); - return; - } object_unref(OBJECT(dev)); } =20 +void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp) +{ + monitor_device_add(qdict, ret_data, true, errp); +} + static DeviceState *find_device_state(const char *id, Error **errp) { Object *obj; @@ -936,7 +940,7 @@ void hmp_device_add(Monitor *mon, const QDict *qdict) { Error *err =3D NULL; =20 - qmp_device_add((QDict *)qdict, NULL, &err); + monitor_device_add((QDict *)qdict, NULL, false, &err); hmp_handle_error(mon, err); } =20 --=20 2.31.1 From nobody Fri May 17 09:18:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632474419; cv=none; d=zohomail.com; s=zohoarc; b=MjKIkIwSSmcZXHjUraTT3M3aIT441TRnVNh8cQmXZyi6fsZldqQTr1jmk65i77SVnTiA18MwnXjrEgn1TvQmVIZ2uR8nHXsDTrbkeQafkysdqIRsEo9Nuyy9xDeZEO4VmqO9gVWjsaEuRgZwj2/yfIPWCChb/9cR6hbf+mS1OAY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632474419; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1+aoIqWAHmOAumQFA38+fhhk4UIxPgmsLdA5N3QEqqE=; b=Pndkm5t/0P9rZTILkuK5iQdLGNq2jUoqcRj+Jlpy8IuuQccZTAJZqCckKqbux+kYe75KRsPWQSZV2x3Ax9D82e+nJ4tDwgUsmfZlUZSIee3oAcMoeWsejCBgZ9kT1QIHbzEPePf2E8cUjtk5DX1KMmEpjnqrFP2AlXLlOJxbJdo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1632474419773417.31494792059846; Fri, 24 Sep 2021 02:06:59 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-491-89qxVsXTNne3OHjTrTLS3w-1; Fri, 24 Sep 2021 05:06:57 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2818E1923764; Fri, 24 Sep 2021 09:06:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0C3251017CE7; Fri, 24 Sep 2021 09:06:52 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CD8ED4EA2F; Fri, 24 Sep 2021 09:06:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18O96pbl024357 for ; Fri, 24 Sep 2021 05:06:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3A3E15E253; Fri, 24 Sep 2021 09:06:51 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 156EA5D9DC; Fri, 24 Sep 2021 09:06:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632474418; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1+aoIqWAHmOAumQFA38+fhhk4UIxPgmsLdA5N3QEqqE=; b=DSBpPiM8XDjxaX0aXu/s/6bjs9AgZr3NHt4mPH+NNh0VfT9cnBtqZGjBNpnHyivzjvX3t8 ca9UHgGVyroOnRO5usg+rBFjyJrtUnRpkS0JzvVwRnOiezXuBjCvx8FTZVaUIwc+Au8dQ7 54u0r58a9eSxVzFyqBDDXK/igaZV7+4= X-MC-Unique: 89qxVsXTNne3OHjTrTLS3w-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH 10/11] vl: Enable JSON syntax for -device Date: Fri, 24 Sep 2021 11:04:26 +0200 Message-Id: <20210924090427.9218-11-kwolf@redhat.com> In-Reply-To: <20210924090427.9218-1-kwolf@redhat.com> References: <20210924090427.9218-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, libvir-list@redhat.com, armbru@redhat.com, its@irrelevant.dk, pbonzini@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632474420341100001 Content-Type: text/plain; charset="utf-8" Like we already do for -object, introduce support for JSON syntax in -device, which can be kept stable in the long term and guarantees that a single code path with identical behaviour is used for both QMP and the command line. Compared to the QemuOpts based code, the parser contains less surprises and has support for non-scalar options (lists and structs). Switching management tools to JSON means that we can more easily change the "human" CLI syntax from QemuOpts to the keyval parser later. In the QAPI schema, a feature flag is added to the device-add command to allow management tools to detect support for this. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- qapi/qdev.json | 15 +++++++++---- softmmu/vl.c | 58 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/qapi/qdev.json b/qapi/qdev.json index b83178220b..cdc8f911b5 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -32,17 +32,23 @@ ## # @device_add: # +# Add a device. +# # @driver: the name of the new device's driver # # @bus: the device's parent bus (device tree path) # # @id: the device's ID, must be unique # -# Additional arguments depend on the type. -# -# Add a device. +# Features: +# @json-cli: If present, the "-device" command line option supports JSON +# syntax with a structure identical to the arguments of this +# command. # # Notes: +# +# Additional arguments depend on the type. +# # 1. For detailed information about this command, please refer to the # 'docs/qdev-device-use.txt' file. # @@ -67,7 +73,8 @@ ## { 'command': 'device_add', 'data': {'driver': 'str', '*bus': 'str', '*id': 'str'}, - 'gen': false } # so we can get the additional arguments + 'gen': false, # so we can get the additional arguments + 'features': ['json-cli'] } =20 ## # @device_del: diff --git a/softmmu/vl.c b/softmmu/vl.c index 55ab70eb97..7596d9da06 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -144,6 +144,12 @@ typedef struct ObjectOption { QTAILQ_ENTRY(ObjectOption) next; } ObjectOption; =20 +typedef struct DeviceOption { + QDict *opts; + Location loc; + QTAILQ_ENTRY(DeviceOption) next; +} DeviceOption; + static const char *cpu_option; static const char *mem_path; static const char *incoming; @@ -151,6 +157,7 @@ static const char *loadvm; static const char *accelerators; static QDict *machine_opts_dict; static QTAILQ_HEAD(, ObjectOption) object_opts =3D QTAILQ_HEAD_INITIALIZER= (object_opts); +static QTAILQ_HEAD(, DeviceOption) device_opts =3D QTAILQ_HEAD_INITIALIZER= (device_opts); static ram_addr_t maxram_size; static uint64_t ram_slots; static int display_remote; @@ -494,21 +501,39 @@ const char *qemu_get_vm_name(void) return qemu_name; } =20 -static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp) +static void default_driver_disable(const char *driver) { - const char *driver =3D qemu_opt_get(opts, "driver"); int i; =20 - if (!driver) - return 0; + if (!driver) { + return; + } + for (i =3D 0; i < ARRAY_SIZE(default_list); i++) { if (strcmp(default_list[i].driver, driver) !=3D 0) continue; *(default_list[i].flag) =3D 0; } +} + +static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp) +{ + const char *driver =3D qemu_opt_get(opts, "driver"); + + default_driver_disable(driver); return 0; } =20 +static void default_driver_check_json(void) +{ + DeviceOption *opt; + + QTAILQ_FOREACH(opt, &device_opts, next) { + const char *driver =3D qdict_get_try_str(opt->opts, "driver"); + default_driver_disable(driver); + } +} + static int parse_name(void *opaque, QemuOpts *opts, Error **errp) { const char *proc_name; @@ -1311,6 +1336,7 @@ static void qemu_disable_default_devices(void) { MachineClass *machine_class =3D MACHINE_GET_CLASS(current_machine); =20 + default_driver_check_json(); qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, NULL); qemu_opts_foreach(qemu_find_opts("global"), @@ -2637,6 +2663,8 @@ static void qemu_init_board(void) =20 static void qemu_create_cli_devices(void) { + DeviceOption *opt; + soundhw_init(); =20 qemu_opts_foreach(qemu_find_opts("fw_cfg"), @@ -2652,6 +2680,13 @@ static void qemu_create_cli_devices(void) rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, &error_fatal); + QTAILQ_FOREACH(opt, &device_opts, next) { + QObject *ret_data; + + loc_push_restore(&opt->loc); + qmp_device_add(opt->opts, &ret_data, &error_fatal); + loc_pop(&opt->loc); + } rom_reset_order_override(); } =20 @@ -3352,9 +3387,18 @@ void qemu_init(int argc, char **argv, char **envp) add_device_config(DEV_USB, optarg); break; case QEMU_OPTION_device: - if (!qemu_opts_parse_noisily(qemu_find_opts("device"), - optarg, true)) { - exit(1); + if (optarg[0] =3D=3D '{') { + QObject *obj =3D qobject_from_json(optarg, &error_fata= l); + DeviceOption *opt =3D g_new0(DeviceOption, 1); + opt->opts =3D qobject_to(QDict, obj); + loc_save(&opt->loc); + assert(opt->opts !=3D NULL); + QTAILQ_INSERT_TAIL(&device_opts, opt, next); + } else { + if (!qemu_opts_parse_noisily(qemu_find_opts("device"), + optarg, true)) { + exit(1); + } } break; case QEMU_OPTION_smp: --=20 2.31.1 From nobody Fri May 17 09:18:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632474423; cv=none; d=zohomail.com; s=zohoarc; b=Qqa9CKk4O5VwCNVkKlzACitoUbGbeaZ8hmfcdKH51X13InUtLlPad/8l3kFu+TcXI6mai3lXCDpYBsJx4JLzqlIk0cpT909tcZL7DKd12QDbjeAHzYVREaBe27W7UPlbilX9RoTLFWUO23G6Gurn2Ids3JKLceeJ7/6e8kNWJe4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632474423; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lf+dwWntK8Cwv6LA2A15j5eQ0oA722s1ysJP3KMCRqQ=; b=hDAB9GSvQtswhiig78fPJU2UOJBzeK6v5348CQsvcPMvv7R1YUhVZj0wXsJNndRVW58i/gxmBPIF5PGrneGuMgdzjpefQOUOauLXeXmGxFVyXtTs0dimgAWkoqYckBdbxHcUPuGkjJhZtEh8U60IRhVZJtYuZEY6h+tQy94Iqk8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1632474423304545.730055561153; Fri, 24 Sep 2021 02:07:03 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-372-9qtodOUONMu-cwFL-s-XwQ-1; Fri, 24 Sep 2021 05:07:00 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0597F1006AA2; Fri, 24 Sep 2021 09:06:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CFB53196FC; Fri, 24 Sep 2021 09:06:55 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A11CC180BAD1; Fri, 24 Sep 2021 09:06:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18O96rOv024371 for ; Fri, 24 Sep 2021 05:06:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 616E85E253; Fri, 24 Sep 2021 09:06:53 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 843435D9DC; Fri, 24 Sep 2021 09:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632474422; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=lf+dwWntK8Cwv6LA2A15j5eQ0oA722s1ysJP3KMCRqQ=; b=idhfjxI6Pvtlgopu/dLHVw21/+L2fTSrVbQxH6hGpzcWRtfsKqZ7rTQ951pvZrG6Fwk857 Asc0nF4MKEEiWvoP2yW9VQ1LPX9/MQN7CW3+EhzX0Zf+SC6tW9vTIsQqW2ccz0K3p7kZh9 N5cKOShqp9Q02NYV6l6x/dnJv0FUsLo= X-MC-Unique: 9qtodOUONMu-cwFL-s-XwQ-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH 11/11] Deprecate stable non-JSON -device and -object Date: Fri, 24 Sep 2021 11:04:27 +0200 Message-Id: <20210924090427.9218-12-kwolf@redhat.com> In-Reply-To: <20210924090427.9218-1-kwolf@redhat.com> References: <20210924090427.9218-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, libvir-list@redhat.com, armbru@redhat.com, its@irrelevant.dk, pbonzini@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632474424271100001 Content-Type: text/plain; charset="utf-8" We want to switch both from QemuOpts to the keyval parser in the future, which results in some incompatibilities, mainly around list handling. Mark the non-JSON version of both as unstable syntax so that management tools switch to JSON and we can later make the change without breaking things. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- docs/about/deprecated.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 3c2be84d80..42f6a478fb 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -160,6 +160,17 @@ Use ``-display sdl`` instead. =20 Use ``-display curses`` instead. =20 +Stable non-JSON ``-device`` and ``-object`` syntax (since 6.2) +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +If you rely on a stable interface for ``-device`` and ``-object`` that doe= sn't +change incompatibly between QEMU versions (e.g. because you are using the = QEMU +command line as a machine interface in scripts rather than interactively),= use +JSON syntax for these options instead. + +There is no intention to remove support for non-JSON syntax entirely, but +future versions may change the way to spell some options. + =20 Plugin argument passing through ``arg=3D`` (since 6.1) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' --=20 2.31.1