From nobody Mon Feb 9 06:34:34 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=1614177999; cv=none; d=zohomail.com; s=zohoarc; b=OlSo83trFMmWIg2G4zbzRxPpIy7SclifHwdoMGMiHWLbb3XDqzwO/g6/ppCK1Ma0u3Aof0wNjvds2SP9XUXcSjs0saPyZhSCBdXV/teRu04jE5gSi4PgMOdJ+Y+ceCx51mjo6dwgxYHn3Rfn8wibjskrNqChXj0TWolR9+O6RGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614177999; 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=lQE7LwEnMXez4+FEX/dIa+IYFEfcoeLiKxAtri633zc=; b=Z95+Rvgi2et/sgBLn2veAmzo5MB96UfDrOV5v3JSsblXWJ58bo9Q4ZjFMLaud3egvf/DekZfRiJX02mVXQRjSicTifCGo+XsVz3Zw+ZnH7wSKgSRPCiv7nJ415IYC3TWaVu+JYA2N4snGCUgr6T5yOx+qH9obWF8GDEPZCbnsGQ= 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 1614177999705546.2186683643549; Wed, 24 Feb 2021 06:46:39 -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-47--Dzo6-ofPP62OuJ2wxXKAA-1; Wed, 24 Feb 2021 09:46:36 -0500 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 7B55A1185CD4; Wed, 24 Feb 2021 13:56:34 +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 3ECE619C46; Wed, 24 Feb 2021 13:56:34 +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 C2F4D18095CC; Wed, 24 Feb 2021 13:56:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11ODuW0j017144 for ; Wed, 24 Feb 2021 08:56:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4ECD762467; Wed, 24 Feb 2021 13:56:32 +0000 (UTC) Received: from merkur.redhat.com (ovpn-114-142.ams2.redhat.com [10.36.114.142]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6FFF5D6AD; Wed, 24 Feb 2021 13:56:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614177998; 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=lQE7LwEnMXez4+FEX/dIa+IYFEfcoeLiKxAtri633zc=; b=T92s5f2Pn3IVr4VWsmxXTjGewBlpUJhLQ5ot2xXu+GSiXS319QbtpPwnsTvXYUX939OH62 rtSsv3fTtv9ud5f4LvA7JoGt97gkPcCo97GelQIUNUOCjlqwUri/OfJaUGD3tIMZUY4LUo y/7Mvg/o7RAMLfFXwimm8NurO1ZUQMk= X-MC-Unique: -Dzo6-ofPP62OuJ2wxXKAA-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH v2 28/31] hmp: QAPIfy object_add Date: Wed, 24 Feb 2021 14:52:52 +0100 Message-Id: <20210224135255.253837-29-kwolf@redhat.com> In-Reply-To: <20210224135255.253837-1-kwolf@redhat.com> References: <20210224135255.253837-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.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) Content-Type: text/plain; charset="utf-8" This switches the HMP command object_add from a QemuOpts-based parser to user_creatable_add_from_str() which uses a keyval parser and enforces the QAPI schema. Apart from being a cleanup, this makes non-scalar properties and help accessible. In order for help to be printed to the monitor instead of stdout, the printf() calls in the help functions are changed to qemu_printf(). Signed-off-by: Kevin Wolf Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Eric Blake --- monitor/hmp-cmds.c | 17 ++--------------- qom/object_interfaces.c | 11 ++++++----- hmp-commands.hx | 2 +- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 3c88a4faef..652cf9ff21 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1670,24 +1670,11 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdic= t) =20 void hmp_object_add(Monitor *mon, const QDict *qdict) { + const char *options =3D qdict_get_str(qdict, "object"); Error *err =3D NULL; - QemuOpts *opts; - Object *obj =3D NULL; - - opts =3D qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err); - if (err) { - goto end; - } =20 - obj =3D user_creatable_add_opts(opts, &err); - qemu_opts_del(opts); - -end: + user_creatable_add_from_str(options, &err); hmp_handle_error(mon, err); - - if (obj) { - object_unref(obj); - } } =20 void hmp_getfd(Monitor *mon, const QDict *qdict) diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 54f0dadfea..c4982dd7a0 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -13,6 +13,7 @@ #include "qemu/help_option.h" #include "qemu/module.h" #include "qemu/option.h" +#include "qemu/qemu-print.h" #include "qapi/opts-visitor.h" #include "qemu/config-file.h" =20 @@ -212,11 +213,11 @@ static void user_creatable_print_types(void) { GSList *l, *list; =20 - printf("List of user creatable objects:\n"); + qemu_printf("List of user creatable objects:\n"); list =3D object_class_get_list_sorted(TYPE_USER_CREATABLE, false); for (l =3D list; l !=3D NULL; l =3D l->next) { ObjectClass *oc =3D OBJECT_CLASS(l->data); - printf(" %s\n", object_class_get_name(oc)); + qemu_printf(" %s\n", object_class_get_name(oc)); } g_slist_free(list); } @@ -247,12 +248,12 @@ static bool user_creatable_print_type_properites(cons= t char *type) } g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0); if (array->len > 0) { - printf("%s options:\n", type); + qemu_printf("%s options:\n", type); } else { - printf("There are no options for %s.\n", type); + qemu_printf("There are no options for %s.\n", type); } for (i =3D 0; i < array->len; i++) { - printf("%s\n", (char *)array->pdata[i]); + qemu_printf("%s\n", (char *)array->pdata[i]); } g_ptr_array_set_free_func(array, g_free); g_ptr_array_free(array, true); diff --git a/hmp-commands.hx b/hmp-commands.hx index d4001f9c5d..6f5d9ce2fb 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1337,7 +1337,7 @@ ERST =20 { .name =3D "object_add", - .args_type =3D "object:O", + .args_type =3D "object:S", .params =3D "[qom-type=3D]type,id=3Dstr[,prop=3Dvalue][,...]", .help =3D "create QOM object", .cmd =3D hmp_object_add, --=20 2.29.2