From nobody Sun Feb 8 19:59:07 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1616164446; cv=none; d=zohomail.com; s=zohoarc; b=hcFk441srs3euatvG2tzUOTz3AHAzSMmCkxl9Hck0nrMk1JDAeU1Xn6rP4b5iDeTiSV3+DOx94GzPNgGZ1QgOlm9NvIk6OdL1R+mLHz1Cp2r1OmhsIyRL0f6uL/vP5kiNGTb5Cmy0E2tf0TIlqBAfLx53RBgQDjOYPG5JogNs/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616164446; h=Content-Type:Content-Transfer-Encoding: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=SnZ/u9Z+vz/0jWXxHkAaiF9kFwkiRwsY4QE0QYf8lic=; b=GKxeVvwEKoFBMAuLe2MS1oukccKvJtRE0rq62135DtCZlb3tniTPBS+zqAqd3D0QtRRcd+SXHErY/f3OLUQ8OGg+9oyjXQg5vEpzjEG7LjgA8JNeILUgnazd6nRVn8WYV8dMwWBsO3P1C30S2XWCxCgtYuOElVYPPIgRmLuasCw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 161616444643289.59116215126267; Fri, 19 Mar 2021 07:34:06 -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-242-m73p7e-HMSOKczbjRV0pqg-1; Fri, 19 Mar 2021 10:34:03 -0400 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 C17CE814339; Fri, 19 Mar 2021 14:33:56 +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 9B49B60C04; Fri, 19 Mar 2021 14:33:56 +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 5519A1800216; Fri, 19 Mar 2021 14:33:56 +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 12JEXrEW027527 for ; Fri, 19 Mar 2021 10:33:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id B1B355D72F; Fri, 19 Mar 2021 14:33:53 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 118775D72E for ; Fri, 19 Mar 2021 14:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616164445; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=SnZ/u9Z+vz/0jWXxHkAaiF9kFwkiRwsY4QE0QYf8lic=; b=LuVDiQoOuITJiW5GQJboj5aeWlqOPURKuvSrQA442jGWuG5Np6YDh3oL/Y3dgqvJP1GuW4 w4Gqc/YhbhK71E99RwgzKgUsNvy9oGDj0P+9uWiWcF/cCs21qht9bSB/iWDQb/DQ0baKvK 5+5xTPq0lIjUT//WinN/e1zCsrwQUvo= X-MC-Unique: m73p7e-HMSOKczbjRV0pqg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v4 04/13] qemu: monitor: Make wrapping of 'props' of 'object-add' optional Date: Fri, 19 Mar 2021 15:33:35 +0100 Message-Id: <421b8a40ad532d1fefe52f1ba5e6fe50972f6cc1.1616164286.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@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" Construct the JSON object which is used for object-add without the 'props' wrapper and add the wrapper only in the monitor code. This simplifies the JSON->commandline generator in the first place and also prepares for upcoming qemu where 'props' will be removed. Signed-off-by: Peter Krempa --- src/qemu/qemu_monitor.c | 68 +++++++++++++++++++++++++++++------------ src/util/virqemu.c | 34 ++++++--------------- 2 files changed, 58 insertions(+), 44 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index c43c6f180e..5a5a98d3e7 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -109,6 +109,9 @@ struct _qemuMonitor { qemuMonitorReportDomainLogError logFunc; void *logOpaque; virFreeCallback logDestroy; + + /* true if qemu no longer wants 'props' sub-object of object-add */ + bool objectAddNoWrap; }; /** @@ -3019,14 +3022,12 @@ qemuMonitorCreateObjectPropsWrap(const char *type, const char *alias, virJSONValuePtr *props) { - virJSONValuePtr ret; - ignore_value(virJSONValueObjectCreate(&ret, - "s:qom-type", type, - "s:id", alias, - "A:props", props, - NULL)); - return ret; + if (virJSONValueObjectPrependString(*props, "id", alias) < 0 || + virJSONValueObjectPrependString(*props, "qom-type", type)) + return NULL; + + return g_steal_pointer(props); } @@ -3046,26 +3047,28 @@ qemuMonitorCreateObjectProps(virJSONValuePtr *props= ret, const char *alias, ...) { - virJSONValuePtr props =3D NULL; - int ret =3D -1; + g_autoptr(virJSONValue) props =3D NULL; + int rc; va_list args; - *propsret =3D NULL; + if (virJSONValueObjectCreate(&props, + "s:qom-type", type, + "s:id", alias, + NULL) < 0) + return -1; + va_start(args, alias); - if (virJSONValueObjectCreateVArgs(&props, args) < 0) - goto cleanup; + rc =3D virJSONValueObjectAddVArgs(props, args); - if (!(*propsret =3D qemuMonitorCreateObjectPropsWrap(type, alias, &pro= ps))) - goto cleanup; + va_end(args); - ret =3D 0; + if (rc < 0) + return -1; - cleanup: - virJSONValueFree(props); - va_end(args); - return ret; + *propsret =3D g_steal_pointer(&props); + return 0; } @@ -3085,6 +3088,7 @@ qemuMonitorAddObject(qemuMonitorPtr mon, virJSONValuePtr *props, char **alias) { + g_autoptr(virJSONValue) pr =3D NULL; const char *type =3D NULL; const char *id =3D NULL; g_autofree char *aliasCopy =3D NULL; @@ -3112,7 +3116,31 @@ qemuMonitorAddObject(qemuMonitorPtr mon, if (alias) aliasCopy =3D g_strdup(id); - if (qemuMonitorJSONAddObject(mon, props) < 0) + if (mon->objectAddNoWrap) { + pr =3D g_steal_pointer(props); + } else { + /* we need to create a wrapper which has the 'qom-type' and 'id' a= nd + * store everything else under a 'props' sub-object */ + g_autoptr(virJSONValue) typeobj =3D NULL; + g_autoptr(virJSONValue) idobj =3D NULL; + + ignore_value(virJSONValueObjectRemoveKey(*props, "qom-type", &type= obj)); + ignore_value(virJSONValueObjectRemoveKey(*props, "id", &idobj)); + + if (!virJSONValueObjectGetKey(*props, 0)) { + virJSONValueFree(*props); + *props =3D NULL; + } + + if (virJSONValueObjectCreate(&pr, + "s:qom-type", type, + "s:id", id, + "A:props", props, + NULL) < 0) + return -1; + } + + if (qemuMonitorJSONAddObject(mon, &pr) < 0) return -1; if (alias) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 57ee42dd16..a206da1852 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -303,12 +303,13 @@ virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr= props, } -static int -virQEMUBuildObjectCommandlineFromJSONInternal(virBufferPtr buf, - const char *type, - const char *alias, - virJSONValuePtr props) +int +virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf, + virJSONValuePtr objprops) { + const char *type =3D virJSONValueObjectGetString(objprops, "qom-type"); + const char *alias =3D virJSONValueObjectGetString(objprops, "id"); + if (!type || !alias) { virReportError(VIR_ERR_INTERNAL_ERROR, _("missing 'type'(%s) or 'alias'(%s) field of QOM '= object'"), @@ -316,31 +317,16 @@ virQEMUBuildObjectCommandlineFromJSONInternal(virBuff= erPtr buf, return -1; } - virBufferAsprintf(buf, "%s,id=3D%s", type, alias); + virBufferAsprintf(buf, "%s,", type); - if (props) { - virBufferAddLit(buf, ","); - if (virQEMUBuildCommandLineJSON(props, buf, NULL, - virQEMUBuildCommandLineJSONArrayBitmap) < = 0) - return -1; - } + if (virQEMUBuildCommandLineJSON(objprops, buf, "qom-type", + virQEMUBuildCommandLineJSONArrayBitmap= ) < 0) + return -1; return 0; } -int -virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf, - virJSONValuePtr objprops) -{ - const char *type =3D virJSONValueObjectGetString(objprops, "qom-type"); - const char *alias =3D virJSONValueObjectGetString(objprops, "id"); - virJSONValuePtr props =3D virJSONValueObjectGetObject(objprops, "props= "); - - return virQEMUBuildObjectCommandlineFromJSONInternal(buf, type, alias,= props); -} - - char * virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr srcdef) { --=20 2.29.2