From nobody Sun Feb 8 12:42:52 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1492090442399445.4086988588672; Thu, 13 Apr 2017 06:34:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2EB38FCE0; Thu, 13 Apr 2017 13:34:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A36677C75B; Thu, 13 Apr 2017 13:34:00 +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 D577B5EC6A; Thu, 13 Apr 2017 13:33:10 +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 v3DDX6Zq013094 for ; Thu, 13 Apr 2017 09:33:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8C5E67835F; Thu, 13 Apr 2017 13:33:06 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2035A7820F for ; Thu, 13 Apr 2017 13:33:04 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id BC2B91041AC; Thu, 13 Apr 2017 15:32:59 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D2EB38FCE0 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D2EB38FCE0 From: Jiri Denemark To: libvir-list@redhat.com Date: Thu, 13 Apr 2017 15:32:55 +0200 Message-Id: <35ca678f0691b534dd5f26a4105c9e54dc7d4fbb.1492090347.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/9] qemu: Pass migratable host CPU model to virCPUUpdate 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 13 Apr 2017 13:34:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We already know from QEMU which CPU features will block migration. Let's use this information to make a migratable copy of the host CPU model and use it for updating guest CPU specification. This will allow us to drop feature filtering from virCPUUpdate where it was just a hack. Signed-off-by: Jiri Denemark --- src/qemu/qemu_capabilities.c | 57 +++++++++++++++++++++++++++++++++++++---= ---- src/qemu/qemu_capabilities.h | 2 ++ src/qemu/qemu_process.c | 2 +- tests/cputest.c | 7 +++++- 4 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 3bfc79c09..1d95e67b3 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -384,6 +384,8 @@ struct _virQEMUCapsHostCPUData { qemuMonitorCPUModelInfoPtr info; /* Host CPU definition reported in domain capabilities. */ virCPUDefPtr reported; + /* Migratable host CPU definition used for updating guest CPU. */ + virCPUDefPtr migratable; }; =20 /* @@ -2136,6 +2138,10 @@ virQEMUCapsHostCPUDataCopy(virQEMUCapsHostCPUDataPtr= dst, !(dst->reported =3D virCPUDefCopy(src->reported))) return -1; =20 + if (src->migratable && + !(dst->migratable =3D virCPUDefCopy(src->migratable))) + return -1; + return 0; } =20 @@ -2145,6 +2151,7 @@ virQEMUCapsHostCPUDataClear(virQEMUCapsHostCPUDataPtr= cpuData) { qemuMonitorCPUModelInfoFree(cpuData->info); virCPUDefFree(cpuData->reported); + virCPUDefFree(cpuData->migratable); =20 memset(cpuData, '\0', sizeof(*cpuData)); } @@ -2483,6 +2490,9 @@ virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps, switch (cpuType) { case VIR_QEMU_CAPS_HOST_CPU_REPORTED: return cpuData->reported; + + case VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE: + return cpuData->migratable; } =20 return NULL; @@ -2492,11 +2502,13 @@ virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps, static void virQEMUCapsSetHostModel(virQEMUCapsPtr qemuCaps, virDomainVirtType type, - virCPUDefPtr cpu) + virCPUDefPtr reported, + virCPUDefPtr migratable) { virQEMUCapsHostCPUDataPtr cpuData =3D virQEMUCapsGetHostCPUData(qemuCa= ps, type); =20 - cpuData->reported =3D cpu; + cpuData->reported =3D reported; + cpuData->migratable =3D migratable; } =20 =20 @@ -3348,26 +3360,39 @@ virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps, } =20 =20 +static virCPUDefPtr +virQEMUCapsNewHostCPUModel(void) +{ + virCPUDefPtr cpu; + + if (VIR_ALLOC(cpu) < 0) + return NULL; + + cpu->type =3D VIR_CPU_TYPE_GUEST; + cpu->mode =3D VIR_CPU_MODE_CUSTOM; + cpu->match =3D VIR_CPU_MATCH_EXACT; + cpu->fallback =3D VIR_CPU_FALLBACK_ALLOW; + + return cpu; +} + + void virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, virCapsPtr caps, virDomainVirtType type) { virCPUDefPtr cpu =3D NULL; + virCPUDefPtr migCPU =3D NULL; virCPUDefPtr hostCPU =3D NULL; int rc; =20 if (!caps || !virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch= )) return; =20 - if (VIR_ALLOC(cpu) < 0) + if (!(cpu =3D virQEMUCapsNewHostCPUModel())) goto error; =20 - cpu->type =3D VIR_CPU_TYPE_GUEST; - cpu->mode =3D VIR_CPU_MODE_CUSTOM; - cpu->match =3D VIR_CPU_MATCH_EXACT; - cpu->fallback =3D VIR_CPU_FALLBACK_ALLOW; - if ((rc =3D virQEMUCapsInitCPUModel(qemuCaps, type, cpu, false)) < 0) { goto error; } else if (rc =3D=3D 1) { @@ -3381,7 +3406,20 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, goto error; } =20 - virQEMUCapsSetHostModel(qemuCaps, type, cpu); + if (!(migCPU =3D virQEMUCapsNewHostCPUModel())) + goto error; + + if ((rc =3D virQEMUCapsInitCPUModel(qemuCaps, type, migCPU, true)) < 0= ) { + goto error; + } else if (rc =3D=3D 1) { + VIR_DEBUG("CPU migratability not provided by QEMU"); + + virCPUDefFree(migCPU); + if (!(migCPU =3D virCPUCopyMigratable(qemuCaps->arch, cpu))) + goto error; + } + + virQEMUCapsSetHostModel(qemuCaps, type, cpu, migCPU); =20 cleanup: virCPUDefFree(hostCPU); @@ -3389,6 +3427,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, =20 error: virCPUDefFree(cpu); + virCPUDefFree(migCPU); virResetLastError(); goto cleanup; } diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index bd147c009..f04f74060 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -453,6 +453,8 @@ int virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCap= s, typedef enum { /* Host CPU definition reported in domain capabilities. */ VIR_QEMU_CAPS_HOST_CPU_REPORTED, + /* Migratable host CPU definition used for updating guest CPU. */ + VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE, } virQEMUCapsHostCPUType; =20 virCPUDefPtr virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c05cd9e7a..6b77a3969 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5311,7 +5311,7 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def, =20 if (virCPUUpdate(def->os.arch, def->cpu, virQEMUCapsGetHostModel(qemuCaps, def->virtType, - VIR_QEMU_CAPS_HOST_CPU_REPORT= ED)) < 0) + VIR_QEMU_CAPS_HOST_CPU_MIGRAT= ABLE)) < 0) goto cleanup; =20 if (virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType, diff --git a/tests/cputest.c b/tests/cputest.c index 528030754..d5e023c40 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -393,6 +393,7 @@ cpuTestUpdate(const void *arg) const struct data *data =3D arg; int ret =3D -1; virCPUDefPtr host =3D NULL; + virCPUDefPtr migHost =3D NULL; virCPUDefPtr cpu =3D NULL; char *result =3D NULL; =20 @@ -400,7 +401,10 @@ cpuTestUpdate(const void *arg) !(cpu =3D cpuTestLoadXML(data->arch, data->name))) goto cleanup; =20 - if (virCPUUpdate(host->arch, cpu, host) < 0) + if (!(migHost =3D virCPUCopyMigratable(data->arch, host))) + goto cleanup; + + if (virCPUUpdate(host->arch, cpu, migHost) < 0) goto cleanup; =20 if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0) @@ -411,6 +415,7 @@ cpuTestUpdate(const void *arg) cleanup: virCPUDefFree(host); virCPUDefFree(cpu); + virCPUDefFree(migHost); VIR_FREE(result); return ret; } --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list