From nobody Mon Feb 9 00:31:03 2026 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