From nobody Mon Feb 9 01:20:48 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=1614178047; cv=none; d=zohomail.com; s=zohoarc; b=eBmlYqqUGQDRImDd8WFgRXGp4WAcRnSf16olgwpNvLi6Mq+TZNqUbvyANeqwvgf0IdJRQQ87IMe7n/j8NX9bYzwcpHW39g/rrzjQveHEp9bbRezEnWMNzA52sfRHOTbA/XVGpmkuBiRPmKfbSWcAGTgok15GiQ5rGyg5Zdlvn58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614178047; 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=gXKPVrh+jgfeYVb1XMNU0rRTCPP0Mh1UYn9crCAR9qA=; b=haLY66kMO9T0Zxrbo1uXpmTu+Z5mj+Q+JnHICiwSEGYinpBGmCtZOK9jowgV2q6tCpsZnKfCklpJ2FEA2/fxA5r0B+y+7qGbB+wVNtSrVXZC8Rc5JquAuyA2cypoVsRHJsVCcCUGDvd7bnR8tXIvPX2aJfopTXl0ASQNRtmQ+40= 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 1614178047011623.779495173762; Wed, 24 Feb 2021 06:47:27 -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-255-HOBIdmTgPN6_gAE7-qeQvw-1; Wed, 24 Feb 2021 09:47:22 -0500 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 D01401970D7E; Wed, 24 Feb 2021 13:56:06 +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 A15125D9D3; Wed, 24 Feb 2021 13:56:06 +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 3F80A58075; Wed, 24 Feb 2021 13:56:06 +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 11ODu55M017083 for ; Wed, 24 Feb 2021 08:56:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id 19C8D1ABE5; Wed, 24 Feb 2021 13:56:05 +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 15AC25D6D3; Wed, 24 Feb 2021 13:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614178045; 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=gXKPVrh+jgfeYVb1XMNU0rRTCPP0Mh1UYn9crCAR9qA=; b=YdinV3CqsU5D3NlrNcUZsJm0Jg+ychvsHvqJEZbgWnoDKYedqsKqE1Yj5SSKdwnZnQxtsj wVDYOGsOwXkDESHR2sos5I9lq7GFhDNHOIR6S+UA0Zn2Cxo3EyXKmEdfG4o61+PqAKi7hh fTZLt9hk0FPjGrnNZOQa4QjgallpEWk= X-MC-Unique: HOBIdmTgPN6_gAE7-qeQvw-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH v2 23/31] qom: Factor out user_creatable_process_cmdline() Date: Wed, 24 Feb 2021 14:52:47 +0100 Message-Id: <20210224135255.253837-24-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.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) Content-Type: text/plain; charset="utf-8" The implementation for --object can be shared between qemu-storage-daemon and other binaries, so move it into a function in qom/object_interfaces.c that is accessible from everywhere. This also requires moving the implementation of qmp_object_add() into a new user_creatable_add_qapi(), because qom/qom-qmp-cmds.c is not linked for tools. user_creatable_print_help_from_qdict() can become static now. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/qom/object_interfaces.h | 41 +++++++++++++++-------- qom/object_interfaces.c | 50 +++++++++++++++++++++++++++- qom/qom-qmp-cmds.c | 20 +---------- storage-daemon/qemu-storage-daemon.c | 22 +----------- 4 files changed, 79 insertions(+), 54 deletions(-) diff --git a/include/qom/object_interfaces.h b/include/qom/object_interface= s.h index 5299603f50..1e6c51b541 100644 --- a/include/qom/object_interfaces.h +++ b/include/qom/object_interfaces.h @@ -2,6 +2,7 @@ #define OBJECT_INTERFACES_H =20 #include "qom/object.h" +#include "qapi/qapi-types-qom.h" #include "qapi/visitor.h" =20 #define TYPE_USER_CREATABLE "user-creatable" @@ -86,6 +87,18 @@ Object *user_creatable_add_type(const char *type, const = char *id, const QDict *qdict, Visitor *v, Error **errp); =20 +/** + * user_creatable_add_qapi: + * @options: the object definition + * @errp: if an error occurs, a pointer to an area to store the error + * + * Create an instance of the user creatable object according to the + * options passed in @opts as described in the QAPI schema documentation. + * + * Returns: the newly created object or NULL on error + */ +void user_creatable_add_qapi(ObjectOptions *options, Error **errp); + /** * user_creatable_add_opts: * @opts: the object definition @@ -131,6 +144,21 @@ typedef bool (*user_creatable_add_opts_predicate)(cons= t char *type); int user_creatable_add_opts_foreach(void *opaque, QemuOpts *opts, Error **errp); =20 +/** + * user_creatable_process_cmdline: + * @optarg: the object definition string as passed on the command line + * + * Create an instance of the user creatable object by parsing optarg + * with a keyval parser and implicit key 'qom-type', converting the + * result to ObjectOptions and calling into qmp_object_add(). + * + * If a help option is given, print help instead and exit. + * + * This function is only meant to be called during command line parsing. + * It exits the process on failure or after printing help. + */ +void user_creatable_process_cmdline(const char *optarg); + /** * user_creatable_print_help: * @type: the QOM type to be added @@ -145,19 +173,6 @@ int user_creatable_add_opts_foreach(void *opaque, */ bool user_creatable_print_help(const char *type, QemuOpts *opts); =20 -/** - * user_creatable_print_help_from_qdict: - * @args: options to create - * - * Prints help considering the other options given in @args (if "qom-type"= is - * given and valid, print properties for the type, otherwise print valid t= ypes) - * - * In contrast to user_creatable_print_help(), this function can't return = that - * no help was requested. It should only be called if we know that help is - * requested and it will always print some help. - */ -void user_creatable_print_help_from_qdict(QDict *args); - /** * user_creatable_del: * @id: the unique ID for the object diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 7d8a4b77b8..efb48249d5 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -2,10 +2,13 @@ =20 #include "qemu/cutils.h" #include "qapi/error.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/qmp/qjson.h" #include "qapi/qobject-input-visitor.h" +#include "qapi/qobject-output-visitor.h" #include "qom/object_interfaces.h" #include "qemu/help_option.h" #include "qemu/module.h" @@ -104,6 +107,29 @@ out: return obj; } =20 +void user_creatable_add_qapi(ObjectOptions *options, Error **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); +} + Object *user_creatable_add_opts(QemuOpts *opts, Error **errp) { Visitor *v; @@ -247,7 +273,7 @@ bool user_creatable_print_help(const char *type, QemuOp= ts *opts) return false; } =20 -void user_creatable_print_help_from_qdict(QDict *args) +static void user_creatable_print_help_from_qdict(QDict *args) { const char *type =3D qdict_get_try_str(args, "qom-type"); =20 @@ -256,6 +282,28 @@ void user_creatable_print_help_from_qdict(QDict *args) } } =20 +void user_creatable_process_cmdline(const char *optarg) +{ + QDict *args; + bool help; + Visitor *v; + ObjectOptions *options; + + args =3D keyval_parse(optarg, "qom-type", &help, &error_fatal); + if (help) { + user_creatable_print_help_from_qdict(args); + exit(EXIT_SUCCESS); + } + + v =3D qobject_input_visitor_new_keyval(QOBJECT(args)); + visit_type_ObjectOptions(v, NULL, &options, &error_fatal); + visit_free(v); + qobject_unref(args); + + user_creatable_add_qapi(options, &error_fatal); + qapi_free_ObjectOptions(options); +} + bool user_creatable_del(const char *id, Error **errp) { QemuOptsList *opts_list; diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c index e577a96adf..2d6f41ecc7 100644 --- a/qom/qom-qmp-cmds.c +++ b/qom/qom-qmp-cmds.c @@ -228,25 +228,7 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const = char *typename, =20 void qmp_object_add(ObjectOptions *options, Error **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); + user_creatable_add_qapi(options, errp); } =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 0dfb9c1448..32b59878a7 100644 --- a/storage-daemon/qemu-storage-daemon.c +++ b/storage-daemon/qemu-storage-daemon.c @@ -38,7 +38,6 @@ #include "qapi/qapi-visit-block-core.h" #include "qapi/qapi-visit-block-export.h" #include "qapi/qapi-visit-control.h" -#include "qapi/qapi-visit-qom.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qstring.h" #include "qapi/qobject-input-visitor.h" @@ -252,27 +251,8 @@ static void process_options(int argc, char *argv[]) break; } case OPTION_OBJECT: - { - QDict *args; - bool help; - Visitor *v; - ObjectOptions *options; - - args =3D keyval_parse(optarg, "qom-type", &help, &error_fa= tal); - if (help) { - user_creatable_print_help_from_qdict(args); - exit(EXIT_SUCCESS); - } - - v =3D qobject_input_visitor_new_keyval(QOBJECT(args)); - visit_type_ObjectOptions(v, NULL, &options, &error_fatal); - visit_free(v); - qobject_unref(args); - - qmp_object_add(options, &error_fatal); - qapi_free_ObjectOptions(options); + user_creatable_process_cmdline(optarg); break; - } default: g_assert_not_reached(); } --=20 2.29.2