From nobody Mon Feb 9 04:46:03 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1606762588; cv=none; d=zohomail.com; s=zohoarc; b=QWxath9GRbpeKA9vOVe1D/MNIe8nglkq5xgV/hHgbY8vvOmakq4j8R80gboGBFGwIKijqry+u9r7B25uky8dTEUbLfD9/HK3aA6d9idOFysKx87LCvW5WfOPXxlAIb9IZdrzf+Fdn3jJHQXRtFmss3YEGObxAwBQlxbPURmHXKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606762588; 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=PaMjC8x09YiCwTHM7sj4gXbAocGtftPR3vE1rjQEL0A=; b=QpWGP5qXVj/Q7m3Ldi9NmpA3X108d7mbwtb/arXMBKJa0MULN963Tk2Y57bKErOWTUAG4VkYectKee517cFXzxn9EdUaAddA8SIOUFfBslCD2w/JtR1bj3URQjqLfmZQ3ettTWrstrgsN02G9UWFVxUwOXsFu/zS0BJZPpgNtXg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606762588936825.9848550940335; Mon, 30 Nov 2020 10:56:28 -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-132-ZeZhSbHpPOyiKlp4pG43JQ-1; Mon, 30 Nov 2020 13:56:24 -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 55F57184215E; Mon, 30 Nov 2020 18:56:18 +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 3270A19D7D; Mon, 30 Nov 2020 18:56:18 +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 F15A21809CB5; Mon, 30 Nov 2020 18:56:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AUIuB2Y014412 for ; Mon, 30 Nov 2020 13:56:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5C13260C6B; Mon, 30 Nov 2020 18:56:11 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0E1560C67 for ; Mon, 30 Nov 2020 18:56:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606762586; 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=PaMjC8x09YiCwTHM7sj4gXbAocGtftPR3vE1rjQEL0A=; b=e8Wm4G0YBBBZIy6JWD3b1im033FJxyGLJx62Cw71GQHsnJ6vB2ACnvylsGtjhg/seuI2v2 5fp+aPis/8WWTHjWK9JRBV3aAabrPDiMjTTlnQQaSbluraX2JCCmlVRorJ6CDjCHPRchY7 p87aaJUmqoeb4pHYmjW/gbUe6ziWaHM= X-MC-Unique: ZeZhSbHpPOyiKlp4pG43JQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 19/24] qemu: monitor: Make wrapping of 'props' of 'object-add' optional Date: Mon, 30 Nov 2020 19:55:32 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.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" 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 | 42 +++++++++---------------- 2 files changed, 62 insertions(+), 48 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index b26fba303d..5da3213976 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -112,6 +112,9 @@ struct _qemuMonitor { qemuMonitorReportDomainLogError logFunc; void *logOpaque; virFreeCallback logDestroy; + + /* true if qemu no longer wants 'props' sub-object of object-add */ + bool objectAddNoWrap; }; /** @@ -3010,14 +3013,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); } @@ -3037,26 +3038,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; } @@ -3076,6 +3079,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; @@ -3103,7 +3107,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 fd8661951a..8a705b79a0 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -320,32 +320,6 @@ virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr = props, } -static int -virQEMUBuildObjectCommandlineFromJSONInternal(virBufferPtr buf, - const char *type, - const char *alias, - virJSONValuePtr props) -{ - if (!type || !alias) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("missing 'type'(%s) or 'alias'(%s) field of QOM '= object'"), - NULLSTR(type), NULLSTR(alias)); - return -1; - } - - virBufferAsprintf(buf, "%s,id=3D%s", type, alias); - - if (props) { - virBufferAddLit(buf, ","); - if (virQEMUBuildCommandLineJSON(props, buf, NULL, false, - virQEMUBuildCommandLineJSONArrayBitmap) < = 0) - return -1; - } - - return 0; -} - - /** * virQEMUBuildObjectCommandlineFromJSON: * @buf: buffer to format output to @@ -363,12 +337,24 @@ virQEMUBuildObjectCommandlineFromJSON(virBufferPtr bu= f, { const char *type =3D virJSONValueObjectGetString(objprops, "qom-type"); const char *alias =3D virJSONValueObjectGetString(objprops, "id"); - virJSONValuePtr props =3D virJSONValueObjectGetObject(objprops, "props= "); + + if (!type || !alias) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("missing 'type'(%s) or 'alias'(%s) field of QOM '= object'"), + NULLSTR(type), NULLSTR(alias)); + return -1; + } if (rawjson) return virJSONValueToBuffer(objprops, buf, false); - return virQEMUBuildObjectCommandlineFromJSONInternal(buf, type, alias,= props); + virBufferAsprintf(buf, "%s,", type); + + if (virQEMUBuildCommandLineJSON(objprops, buf, "qom-type", false, + virQEMUBuildCommandLineJSONArrayBitmap= ) < 0) + return -1; + + return 0; } --=20 2.28.0