From nobody Sun Feb 8 14:11:52 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=1615222747; cv=none; d=zohomail.com; s=zohoarc; b=PwgfJwRJ1VjiPhDQ5CcbM+27ehi4sWvXEMiYftuST0J0m3l+bPiIJYaGARiqsrjYQW1q76z0BuqiDWAgzVdlFDPusyU7Z1WFUELG375bjMcq8F3HTMNjn8jcnV+mtYF/709vOKH5x6iYNcYp7QRJIvCbDzftAaytp1dpEeixs1k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615222747; 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=+NhKB09cltNik9nPFX/Lufn/xJNp2jwQ7EzFNhx4MLk=; b=LYybbXJ0qZL1F2IW/FxUxaaWPFa4yCUwbXgw3yO8fl7ykyVu7ukWG78jGVFVjFCKakAXbwp5OxxTPMj3a814Ye9cShx7wJMJBUJiqRYK3cSoqnl1WFETx1q7JVtAXeRMzdJdWCpZUdeTNlzgJMZIv//tG8rl1zC+VYHOkj1FOcM= 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 1615222747850511.538281889058; Mon, 8 Mar 2021 08:59:07 -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-66-HgdP3jMhPDO6Ib9FoRoeyA-1; Mon, 08 Mar 2021 11:58:04 -0500 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 0ECE2881290; Mon, 8 Mar 2021 16:57:58 +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 E06182BFEE; Mon, 8 Mar 2021 16:57:57 +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 A49E31809C8B; Mon, 8 Mar 2021 16:57: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 128Gvubn023746 for ; Mon, 8 Mar 2021 11:57:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8A9344278; Mon, 8 Mar 2021 16:57:56 +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 A84A14EF6B; Mon, 8 Mar 2021 16:57:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615222746; 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=+NhKB09cltNik9nPFX/Lufn/xJNp2jwQ7EzFNhx4MLk=; b=RmQ6A3H63/Dkzw0deRZ7zQIrEXcpHBjNX4JL+/2RWF7prpWTw7IWCglA4IK/7ivNwbSkOC bgw0DSQiMDK2QpgdvBRiA6vF3CA9zmby9VcQ44NaAuqVHWZE4gyhWsRzZlLFy+t8kBzJCe 4H+XZJGht/g8NggYUbL5hrAZq8zqSVo= X-MC-Unique: HgdP3jMhPDO6Ib9FoRoeyA-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH v3 28/30] qom: Add user_creatable_parse_str() Date: Mon, 8 Mar 2021 17:54:38 +0100 Message-Id: <20210308165440.386489-29-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.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) Content-Type: text/plain; charset="utf-8" The system emulator has a more complicated way of handling command line options in that it reorders options before it processes them. This means that parsing object options and creating the object happen at two different points. Split the parsing part into a separate function that can be reused by the system emulator command line. Signed-off-by: Kevin Wolf Acked-by: Peter Krempa Reviewed-by: Eric Blake --- include/qom/object_interfaces.h | 15 +++++++++++++++ qom/object_interfaces.c | 20 ++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/include/qom/object_interfaces.h b/include/qom/object_interface= s.h index 07511e6cff..fb32330901 100644 --- a/include/qom/object_interfaces.h +++ b/include/qom/object_interfaces.h @@ -144,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_parse_str: + * @optarg: the object definition string as passed on the command line + * @errp: if an error occurs, a pointer to an area to store the error + * + * Parses the option for the user creatable object with a keyval parser and + * implicit key 'qom-type', converting the result to ObjectOptions. + * + * If a help option is given, print help instead. + * + * Returns: ObjectOptions on success, NULL when an error occurred (*errp i= s set + * then) or help was printed (*errp is not set). + */ +ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp); + /** * user_creatable_add_from_str: * @optarg: the object definition string as passed on the command line diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 6dcab60f09..62d7db7629 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -292,7 +292,7 @@ static void user_creatable_print_help_from_qdict(QDict = *args) } } =20 -bool user_creatable_add_from_str(const char *optarg, Error **errp) +ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp) { ERRP_GUARD(); QDict *args; @@ -302,12 +302,12 @@ bool user_creatable_add_from_str(const char *optarg, = Error **errp) =20 args =3D keyval_parse(optarg, "qom-type", &help, errp); if (*errp) { - return false; + return NULL; } if (help) { user_creatable_print_help_from_qdict(args); qobject_unref(args); - return false; + return NULL; } =20 v =3D qobject_input_visitor_new_keyval(QOBJECT(args)); @@ -315,12 +315,20 @@ bool user_creatable_add_from_str(const char *optarg, = Error **errp) visit_free(v); qobject_unref(args); =20 - if (*errp) { - goto out; + return options; +} + +bool user_creatable_add_from_str(const char *optarg, Error **errp) +{ + ERRP_GUARD(); + ObjectOptions *options; + + options =3D user_creatable_parse_str(optarg, errp); + if (!options) { + return false; } =20 user_creatable_add_qapi(options, errp); -out: qapi_free_ObjectOptions(options); return !*errp; } --=20 2.29.2