From nobody Sun Feb 8 14:53:32 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=1615222762; cv=none; d=zohomail.com; s=zohoarc; b=YHiieAmpZaAizGHJhFqrwW2Mra1JP0e7hqtWMZim4dwb7XY79IztOWd9mH9GNRRLbsoLhwjzejncjnLRQEtGkXxu4x1GBmE7p/vftUwki5lq20Pml3QfdTNI2pVfrxj0YbNjPfGdNu2cdxEfC2ttD8E8/MXR/T3iejeSHi71iDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615222762; 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=yaVzR3CIb/IhxKfm+tM3X0sgzc3ZsPckmXm8Sq23LFA=; b=nWi/G/Oq213+0QuA44AyQeOGYMoXmJm5SrHWhIGgsX71e0KMngYGfkt7iH6nT2PbwsWDD7vlm4Z3rAMRGzOOet3QlLZx2GV8fA520tdNVYkYgF5D1BqnEERax2TRA10COKQRwuP0BVW0lNdFiLH9PKODsUxaMrcb+R9XGFBuBX4= 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) header.from= 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 1615222762247416.50109663751596; Mon, 8 Mar 2021 08:59:22 -0800 (PST) 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-535-oNU3SK3EOiS-DLSJGP6jag-1; Mon, 08 Mar 2021 11:56:48 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ED2151054F97; Mon, 8 Mar 2021 16:56:41 +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 CBD7360C17; Mon, 8 Mar 2021 16:56:41 +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 9722C57DC9; Mon, 8 Mar 2021 16:56:41 +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 128Gue0T023136 for ; Mon, 8 Mar 2021 11:56:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id A0B354EF6B; Mon, 8 Mar 2021 16:56:40 +0000 (UTC) Received: from merkur.fritz.box (ovpn-112-100.ams2.redhat.com [10.36.112.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id AADE95D9DE; Mon, 8 Mar 2021 16:56:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615222761; 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=yaVzR3CIb/IhxKfm+tM3X0sgzc3ZsPckmXm8Sq23LFA=; b=YSFXgDY0OuApWw6Ps9CoMCPuQ/Q02MzhBiDriFYE1xjLKvk9ETp+gu5Lg4+xi4ISJkgMvO u4lwzykUaZZ0f3fUvZId1AkB6DDHX+r/8Xv3dTd1/p/qaeNrm0+mbkMo2NU7OExMseQEHM AKc5KI1A6AcQnfQcozV1HD1pjYmdrmw= X-MC-Unique: oNU3SK3EOiS-DLSJGP6jag-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH v3 18/30] qapi/qom: QAPIfy object-add Date: Mon, 8 Mar 2021 17:54:28 +0100 Message-Id: <20210308165440.386489-19-kwolf@redhat.com> In-Reply-To: <20210308165440.386489-1-kwolf@redhat.com> References: <20210308165440.386489-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, lvivier@redhat.com, thuth@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, libvir-list@redhat.com, jasowang@redhat.com, mreitz@redhat.com, kraxel@redhat.com, pbonzini@redhat.com, dgilbert@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.12 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) Content-Type: text/plain; charset="utf-8" This converts object-add from 'gen': false to the ObjectOptions QAPI type. As an immediate benefit, clients can now use QAPI schema introspection for user creatable QOM objects. It is also the first step towards making the QAPI schema the only external interface for the creation of user creatable objects. Once all other places (HMP and command lines of the system emulator and all tools) go through QAPI, too, some object implementations can be simplified because some checks (e.g. that mandatory options are set) are already performed by QAPI, and in another step, QOM boilerplate code could be generated from the schema. Signed-off-by: Kevin Wolf Acked-by: Peter Krempa Reviewed-by: Eric Blake --- qapi/qom.json | 11 +---------- include/qom/object_interfaces.h | 7 ------- hw/block/xen-block.c | 16 ++++++++-------- monitor/misc.c | 2 -- qom/qom-qmp-cmds.c | 25 +++++++++++++++++++++++-- storage-daemon/qemu-storage-daemon.c | 2 -- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/qapi/qom.json b/qapi/qom.json index 0fd8563693..5b8a5da16f 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -844,13 +844,6 @@ # # Create a QOM object. # -# @qom-type: the class name for the object to be created -# -# @id: the name of the new object -# -# Additional arguments depend on qom-type and are passed to the backend -# unchanged. -# # Returns: Nothing on success # Error if @qom-type is not a valid class name # @@ -864,9 +857,7 @@ # <- { "return": {} } # ## -{ 'command': 'object-add', - 'data': {'qom-type': 'str', 'id': 'str'}, - 'gen': false } # so we can get the additional arguments +{ 'command': 'object-add', 'data': 'ObjectOptions', 'boxed': true } =20 ## # @object-del: diff --git a/include/qom/object_interfaces.h b/include/qom/object_interface= s.h index 07d5cc8832..9b9938b8c0 100644 --- a/include/qom/object_interfaces.h +++ b/include/qom/object_interfaces.h @@ -196,11 +196,4 @@ bool user_creatable_del(const char *id, Error **errp); */ void user_creatable_cleanup(void); =20 -/** - * qmp_object_add: - * - * QMP command handler for object-add. See the QAPI schema for documentati= on. - */ -void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp); - #endif diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index a3b69e2709..ac82d54063 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -836,17 +836,17 @@ static XenBlockIOThread *xen_block_iothread_create(co= nst char *id, { ERRP_GUARD(); XenBlockIOThread *iothread =3D g_new(XenBlockIOThread, 1); - QDict *opts; - QObject *ret_data =3D NULL; + ObjectOptions *opts; =20 iothread->id =3D g_strdup(id); =20 - opts =3D qdict_new(); - qdict_put_str(opts, "qom-type", TYPE_IOTHREAD); - qdict_put_str(opts, "id", id); - qmp_object_add(opts, &ret_data, errp); - qobject_unref(opts); - qobject_unref(ret_data); + opts =3D g_new(ObjectOptions, 1); + *opts =3D (ObjectOptions) { + .qom_type =3D OBJECT_TYPE_IOTHREAD, + .id =3D g_strdup(id), + }; + qmp_object_add(opts, errp); + qapi_free_ObjectOptions(opts); =20 if (*errp) { g_free(iothread->id); diff --git a/monitor/misc.c b/monitor/misc.c index a7650ed747..42efd9e2ab 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -235,8 +235,6 @@ static void monitor_init_qmp_commands(void) qmp_query_qmp_schema, QCO_ALLOW_PRECONFIG); qmp_register_command(&qmp_commands, "device_add", qmp_device_add, QCO_NO_OPTIONS); - qmp_register_command(&qmp_commands, "object-add", qmp_object_add, - QCO_NO_OPTIONS); =20 QTAILQ_INIT(&qmp_cap_negotiation_commands); qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities", diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c index 19fd5e117f..e577a96adf 100644 --- a/qom/qom-qmp-cmds.c +++ b/qom/qom-qmp-cmds.c @@ -19,8 +19,11 @@ #include "qapi/error.h" #include "qapi/qapi-commands-qdev.h" #include "qapi/qapi-commands-qom.h" +#include "qapi/qapi-visit-qom.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" +#include "qapi/qobject-input-visitor.h" +#include "qapi/qobject-output-visitor.h" #include "qemu/cutils.h" #include "qom/object_interfaces.h" #include "qom/qom-qobject.h" @@ -223,9 +226,27 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const = char *typename, return prop_list; } =20 -void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp) +void qmp_object_add(ObjectOptions *options, Error **errp) { - user_creatable_add_dict(qdict, false, errp); + Visitor *v; + QObject *qobj; + QDict *props; + Object *obj; + + v =3D qobject_output_visitor_new(&qobj); + visit_type_ObjectOptions(v, NULL, &options, &error_abort); + visit_complete(v, &qobj); + visit_free(v); + + props =3D qobject_to(QDict, qobj); + qdict_del(props, "qom-type"); + qdict_del(props, "id"); + + v =3D qobject_input_visitor_new(QOBJECT(props)); + obj =3D user_creatable_add_type(ObjectType_str(options->qom_type), + options->id, props, v, errp); + object_unref(obj); + visit_free(v); } =20 void qmp_object_del(const char *id, Error **errp) diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-sto= rage-daemon.c index 23756fc8e5..a1bcbacf05 100644 --- a/storage-daemon/qemu-storage-daemon.c +++ b/storage-daemon/qemu-storage-daemon.c @@ -148,8 +148,6 @@ static void init_qmp_commands(void) qmp_init_marshal(&qmp_commands); qmp_register_command(&qmp_commands, "query-qmp-schema", qmp_query_qmp_schema, QCO_ALLOW_PRECONFIG); - qmp_register_command(&qmp_commands, "object-add", qmp_object_add, - QCO_NO_OPTIONS); =20 QTAILQ_INIT(&qmp_cap_negotiation_commands); qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities", --=20 2.29.2