From nobody Fri Dec 19 02:51:00 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 ARC-Seal: i=1; a=rsa-sha256; t=1571153764; cv=none; d=zoho.com; s=zohoarc; b=d3BQhC/KdkwwZcBbZMvP9zkIZsmPSAyTB6ZSVGCgGuaFuBCHKzVmpg9MNi5YpPi0PE6Dk7p7/znC1w5o3P6IKkh2r6H2p8IsLphUAME3+yUQ7iQZZLw62FfpORKsh/OkIgCsrhZpsC6uiZDn0KZjM90Por9T8Yk8sjqjF83SM0Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571153764; 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=xVAoAsLc25mpRqapTzZ6yvJ17Ne2xqSojHLjF/V9biU=; b=OdNWjmcDRhy8lJ/H3Je6XbCYF4GOA0rMVgrhuTf4mU6YJgmoP9BcKR7UN5+kVOreBokmQrkyL1gc0wIYAVldNWVYkIzUo6xzX8si8bRf9R9Y0+0rtDQygRxeX0QNoZFbLJFs/vjwsSVDCaPSS3VeJeDUL0gElx4OWgSaSI+fEVE= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1571153764330506.6544043128147; Tue, 15 Oct 2019 08:36:04 -0700 (PDT) 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 920252108; Tue, 15 Oct 2019 15:36:02 +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 59D2210027C0; Tue, 15 Oct 2019 15:36:02 +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 E5BEE180BA99; Tue, 15 Oct 2019 15:36:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9FFZH2h024715 for ; Tue, 15 Oct 2019 11:35:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 679B95D9E2; Tue, 15 Oct 2019 15:35:17 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.188]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1794D5D9CD for ; Tue, 15 Oct 2019 15:35:14 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 40513101CD5; Tue, 15 Oct 2019 17:35:09 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:34:45 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 09/31] qemu: Change return type of virQEMUCapsFetchCPUDefinitions 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: , 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.6.2 (mx1.redhat.com [10.5.110.71]); Tue, 15 Oct 2019 15:36:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The function would return a valid virDomainCapsCPUModelsPtr with empty CPU models list if query-cpu-definitions exists in QEMU, but returns GenericError meaning it's not in fact implemented. This behaviour is a bit strange especially after such virDomainCapsCPUModels structure is stored in capabilities XML and parsed back, which will result in NULL virDomainCapsCPUModelsPtr rather than a structure containing nothing. Let's just keep virDomainCapsCPUModelsPtr NULL if the QMP command is not implemented and change the return value to int so that callers can easily check for failure or success. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 2: - new patch src/qemu/qemu_capabilities.c | 34 +++++++++++++++++++++------------- src/qemu/qemu_capabilities.h | 5 +++-- src/qemu/qemu_process.c | 17 ++++++++++------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index b608eb1a43..6fa5e06edb 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2452,17 +2452,26 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCapsPtr qemu= Caps, } =20 =20 -virDomainCapsCPUModelsPtr +int virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon, - virArch arch) + virArch arch, + virDomainCapsCPUModelsPtr *cpuModels) { virDomainCapsCPUModelsPtr models =3D NULL; qemuMonitorCPUDefInfoPtr *cpus =3D NULL; int ncpus =3D 0; size_t i; + int ret =3D -1; + + *cpuModels =3D NULL; =20 if ((ncpus =3D qemuMonitorGetCPUDefinitions(mon, &cpus)) < 0) - return NULL; + return -1; + + if (ncpus =3D=3D 0) { + ret =3D 0; + goto cleanup; + } =20 /* QEMU 2.11 for Power renamed all CPU models to lower case, we need to * translate them back to libvirt's upper case model names. */ @@ -2471,7 +2480,7 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon, char **name; =20 if (virCPUGetModels(arch, &libvirtModels) < 0) - goto error; + goto cleanup; =20 for (name =3D libvirtModels; name && *name; name++) { for (i =3D 0; i < ncpus; i++) { @@ -2480,13 +2489,13 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon, =20 VIR_FREE(cpus[i]->name); if (VIR_STRDUP(cpus[i]->name, *name) < 0) - goto error; + goto cleanup; } } } =20 if (!(models =3D virDomainCapsCPUModelsNew(ncpus))) - goto error; + goto cleanup; =20 for (i =3D 0; i < ncpus; i++) { virDomainCapsCPUUsable usable =3D VIR_DOMCAPS_CPU_USABLE_UNKNOWN; @@ -2498,19 +2507,18 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon, =20 if (virDomainCapsCPUModelsAddSteal(models, &cpus[i]->name, usable, &cpus[i]->blockers) < 0) - goto error; + goto cleanup; } =20 + VIR_STEAL_PTR(*cpuModels, models); + ret =3D 0; + cleanup: for (i =3D 0; i < ncpus; i++) qemuMonitorCPUDefInfoFree(cpus[i]); VIR_FREE(cpus); - return models; - - error: virObjectUnref(models); - models =3D NULL; - goto cleanup; + return ret; } =20 =20 @@ -2524,7 +2532,7 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemu= Caps, if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_DEFINITIONS)) return 0; =20 - if (!(models =3D virQEMUCapsFetchCPUDefinitions(mon, qemuCaps->arch))) + if (virQEMUCapsFetchCPUDefinitions(mon, qemuCaps->arch, &models) < 0) return -1; =20 if (tcg || !virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 67dccc522e..ba3fe3d2b6 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -573,8 +573,9 @@ virDomainCapsCPUModelsPtr virQEMUCapsGetCPUDefinitions(= virQEMUCapsPtr qemuCaps, virDomainVirtType t= ype, const char **modelW= hitelist, const char **modelB= lacklist); -virDomainCapsCPUModelsPtr virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mo= n, - virArch arch); +int virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon, + virArch arch, + virDomainCapsCPUModelsPtr *cpuModels); =20 typedef enum { /* Host CPU definition reported in domain capabilities. */ diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index f37acab9e4..93fe994f8e 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4353,27 +4353,30 @@ qemuProcessUpdateAndVerifyCPU(virQEMUDriverPtr driv= er, } =20 =20 -static virDomainCapsCPUModelsPtr +static int qemuProcessFetchCPUDefinitions(virQEMUDriverPtr driver, virDomainObjPtr vm, - qemuDomainAsyncJob asyncJob) + qemuDomainAsyncJob asyncJob, + virDomainCapsCPUModelsPtr *cpuModels) { qemuDomainObjPrivatePtr priv =3D vm->privateData; virDomainCapsCPUModelsPtr models =3D NULL; + int rc; =20 if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) goto error; =20 - models =3D virQEMUCapsFetchCPUDefinitions(priv->mon, vm->def->os.arch); + rc =3D virQEMUCapsFetchCPUDefinitions(priv->mon, vm->def->os.arch, &mo= dels); =20 - if (qemuDomainObjExitMonitor(driver, vm) < 0) + if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) goto error; =20 - return models; + *cpuModels =3D models; + return 0; =20 error: virObjectUnref(models); - return NULL; + return -1; } =20 =20 @@ -4398,7 +4401,7 @@ qemuProcessUpdateCPU(virQEMUDriverPtr driver, if (qemuProcessUpdateLiveGuestCPU(vm, cpu, disabled) < 0) goto cleanup; =20 - if (!(models =3D qemuProcessFetchCPUDefinitions(driver, vm, asyncJob))= || + if (qemuProcessFetchCPUDefinitions(driver, vm, asyncJob, &models) < 0 = || virCPUTranslate(vm->def->os.arch, vm->def->cpu, models) < 0) goto cleanup; =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list