From nobody Mon Feb 9 00:55:51 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=1614182343; cv=none; d=zohomail.com; s=zohoarc; b=JTPJ7vKzFnXqdfyxMYIo5DUIkUJLHRmmgvQTQwERCZ4g8rxprvsjblPKUfJQN4Ae/2jhbnFij8anyChbaXFFFIZNIThJAG+Z3e+Qzwc2OMwIaeME/nnELUYtYztgDKce5VP7JTtErCNl3OCFslyQpgvZFeYqoVGxB3A419fa6l8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614182343; 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=7DL3ho8yL8wFbtq3mC6gYm/pns6E0h+ZpHQOE92yiFk=; b=PoHFqBXyGbCkBe0mUYFLm7H8DD67s4IYmY7Gw0O8UXnrRqep89K7NBJsRpnt2fEvamnwsN92cbSIDNLjmJoTdYPxB3KlI28nobTU5/fGZO+oexW9pfeYg5IuR7H1mAS4g8SFuvCt4TlHDGk/RvzxwQDwJ2HEBIgoplNQgPd0wUo= 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 1614182343343329.2478632625945; Wed, 24 Feb 2021 07:59:03 -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-65-XsoaHIZ7OyK2UAJwkuvn3Q-1; Wed, 24 Feb 2021 10:58:59 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A9E6E4963; Wed, 24 Feb 2021 15:58:47 +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 2802C60D79; Wed, 24 Feb 2021 15:58:47 +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 DCBE158078; Wed, 24 Feb 2021 15:58:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11OFwI90010820 for ; Wed, 24 Feb 2021 10:58:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id A658510023AB; Wed, 24 Feb 2021 15:58:18 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A82F100239F for ; Wed, 24 Feb 2021 15:58:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614182342; 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=7DL3ho8yL8wFbtq3mC6gYm/pns6E0h+ZpHQOE92yiFk=; b=MtAhfeiLf0x5+qFMbuU/k7KIAiIKRAhFheF/0SyMwmYMEp89d/LZmXD0I9iuHrGf/uHhI+ ARsE9Qee+GyPV9FP8+euFolJ2gqGfhZr8gpAMTZ6ub10L83DBtmDCi8WswtBkUGMpahDBa yOjfOB8akJnxqGMt2PjaoN/w8U1h4Lw= X-MC-Unique: XsoaHIZ7OyK2UAJwkuvn3Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 07/12] qemu: monitor: Make wrapping of 'props' of 'object-add' optional Date: Wed, 24 Feb 2021 16:58:01 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.13 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 ed35da17e1..8b88c8f922 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; }; /** @@ -3012,14 +3015,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); } @@ -3039,26 +3040,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; } @@ -3078,6 +3081,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; @@ -3105,7 +3109,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 c420b144e1..5fe142394c 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -303,32 +303,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, - virQEMUBuildCommandLineJSONArrayBitmap) < = 0) - return -1; - } - - return 0; -} - - /** * virQEMUBuildObjectCommandlineFromJSON: * @buf: buffer to format output to @@ -346,12 +320,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", + virQEMUBuildCommandLineJSONArrayBitmap= ) < 0) + return -1; + + return 0; } --=20 2.29.2