From nobody Tue Feb 10 16:18:59 2026 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 154734104257677.4553193325612; Sat, 12 Jan 2019 16:57:22 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D9F89A7FED; Sun, 13 Jan 2019 00:57:20 +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 A687A104812D; Sun, 13 Jan 2019 00:57:20 +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 4F288184B54C; Sun, 13 Jan 2019 00:57:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0D0vJMK001760 for ; Sat, 12 Jan 2019 19:57:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id EEB6F81748; Sun, 13 Jan 2019 00:57:18 +0000 (UTC) Received: from cv1.lan (ovpn-126-68.rdu2.redhat.com [10.10.126.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B75C18258; Sun, 13 Jan 2019 00:57:17 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Sat, 12 Jan 2019 18:50:20 -0600 Message-Id: <20190113005032.17880-22-cventeic@redhat.com> In-Reply-To: <20190113005032.17880-1-cventeic@redhat.com> References: <20190113005032.17880-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , david@redhat.com, mprivozn@redhat.com, jdenemar@redhat.com, chris@venteicher.org Subject: [libvirt] [PATCH v6 21/33] qemu_monitor: Introduce qemuMonitorCPUModelInfoNew 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sun, 13 Jan 2019 00:57:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use a helper function to allocate and initializes CPU Model Info structs. Signed-off-by: Chris Venteicher --- src/qemu/qemu_capabilities.c | 8 ++++---- src/qemu/qemu_monitor.c | 27 ++++++++++++++++++++++----- src/qemu/qemu_monitor.h | 2 ++ src/qemu/qemu_monitor_json.c | 5 +---- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index bac8487a78..02911a2a10 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3063,16 +3063,16 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemu= Caps, goto cleanup; } =20 - if (VIR_ALLOC(hostCPU) < 0) - goto cleanup; - - if (!(hostCPU->name =3D virXMLPropString(hostCPUNode, "model"))) { + if (!(str =3D virXMLPropString(hostCPUNode, "model"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing host CPU model name in QEMU " "capabilities cache")); goto cleanup; } =20 + if (!(hostCPU =3D qemuMonitorCPUModelInfoNew(str))) + goto cleanup; + if (!(str =3D virXMLPropString(hostCPUNode, "migratability")) || (val =3D virTristateBoolTypeFromString(str)) <=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 7ce5bd668e..815a30c275 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3686,6 +3686,26 @@ qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon, } =20 =20 +qemuMonitorCPUModelInfoPtr +qemuMonitorCPUModelInfoNew(const char *name) +{ + qemuMonitorCPUModelInfoPtr ret =3D NULL; + qemuMonitorCPUModelInfoPtr model; + + if (VIR_ALLOC(model) < 0) + return NULL; + + if (VIR_STRDUP(model->name, name) < 0) + goto cleanup; + + VIR_STEAL_PTR(ret, model); + + cleanup: + qemuMonitorCPUModelInfoFree(model); + return ret; +} + + void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info) { @@ -3709,18 +3729,15 @@ qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfo= Ptr model_info) qemuMonitorCPUModelInfoPtr qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig) { - qemuMonitorCPUModelInfoPtr copy; + qemuMonitorCPUModelInfoPtr copy =3D NULL; size_t i; =20 - if (VIR_ALLOC(copy) < 0) + if (!(copy =3D qemuMonitorCPUModelInfoNew(orig->name))) goto error; =20 if (VIR_ALLOC_N(copy->props, orig->nprops) < 0) goto error; =20 - if (VIR_STRDUP(copy->name, orig->name) < 0) - goto error; - copy->migratability =3D orig->migratability; copy->nprops =3D orig->nprops; =20 diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 8fcac8850f..d17bda75c3 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1067,6 +1067,8 @@ int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mo= n, =20 void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info); =20 +qemuMonitorCPUModelInfoPtr qemuMonitorCPUModelInfoNew(const char *name); + qemuMonitorCPUModelInfoPtr qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig); =20 diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 1f7eb20a25..dcb468c747 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5642,10 +5642,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr m= on, goto cleanup; } =20 - if (VIR_ALLOC(machine_model) < 0) - goto cleanup; - - if (VIR_STRDUP(machine_model->name, cpu_name) < 0) + if (!(machine_model =3D qemuMonitorCPUModelInfoNew(cpu_name))) goto cleanup; =20 if (VIR_ALLOC_N(machine_model->props, virJSONValueObjectKeysNumber(cpu= _props)) < 0) --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list