From nobody Wed May 14 11:48:24 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1524110820547874.894581109687; Wed, 18 Apr 2018 21:07:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E911F3187162; Thu, 19 Apr 2018 04:06:58 +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 9E67B5E1B5; Thu, 19 Apr 2018 04:06:58 +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 3764D4CA9C; Thu, 19 Apr 2018 04:06:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3J46qW5002588 for ; Thu, 19 Apr 2018 00:06:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id C223510F1BF4; Thu, 19 Apr 2018 04:06:52 +0000 (UTC) Received: from cv1.lan (ovpn-123-247.rdu2.redhat.com [10.10.123.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7071110F1BF5; Thu, 19 Apr 2018 04:06:52 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Wed, 18 Apr 2018 23:06:46 -0500 Message-Id: <20180419040647.32300-3-cventeic@redhat.com> In-Reply-To: <20180419040647.32300-1-cventeic@redhat.com> References: <20180419040647.32300-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Chris Venteicher Subject: [libvirt] [PATCHv2 2/3] qemu_monitor_json: Build Json CPU Model Info 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 19 Apr 2018 04:06:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Function qemuMonitorJSONBuildCPUModelInfoToJSON builds and returns JSON of form {"model": {"name": "IvyBridge", "props": {}}} from qemuMonitorCPUModelInfo. Function qemuMonitorJSONBuildCPUModelInfoToJSON returns virJsonValuePtr on success and NULL on failure. --- src/qemu/qemu_monitor_json.c | 48 ++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 48 insertions(+) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 4368aaaa0..44c1b2f15 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5337,6 +5337,54 @@ qemuMonitorJSONParseCPUModelProperty(const char *key, return 0; } =20 +/* model_json: {"model": {"name": "IvyBridge", "props": {}}} + */ +static virJSONValuePtr +qemuMonitorJSONBuildCPUModelInfoToJSON(qemuMonitorCPUModelInfoPtr model) +{ + virJSONValuePtr cpu_props =3D NULL; + virJSONValuePtr model_json =3D NULL; + size_t i; + + if (!(cpu_props =3D virJSONValueNewObject())) + goto cleanup; + + for (i =3D 0; i < model->nprops; i++) { + qemuMonitorCPUPropertyPtr prop =3D model->props + i; + + switch (prop->type) { + case QEMU_MONITOR_CPU_PROPERTY_BOOLEAN: + if (virJSONValueObjectAppendBoolean(cpu_props, prop->name, pro= p->value.boolean) < 0) + goto cleanup; + break; + + case QEMU_MONITOR_CPU_PROPERTY_STRING: + if (virJSONValueObjectAppendString(cpu_props, prop->name, prop= ->value.string) < 0) + goto cleanup; + break; + + case QEMU_MONITOR_CPU_PROPERTY_NUMBER: + if (virJSONValueObjectAppendNumberLong(cpu_props, prop->name, = prop->value.number) < 0) + goto cleanup; + break; + + case QEMU_MONITOR_CPU_PROPERTY_LAST: + default: + virReportEnumRangeError(qemuMonitorCPUPropertyPtr, prop->type); + goto cleanup; + } + } + + if (virJSONValueObjectCreate(&model_json, "s:name", model->name, + "a:props", &cpu_props, NULL)= < 0) { + virJSONValueFree(cpu_props); + goto cleanup; + } + + cleanup: + return model_json; +} + /* model_json: {"model": {"name": "IvyBridge", "props": {}}} */ static qemuMonitorCPUModelInfoPtr --=20 2.14.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list