From nobody Thu Mar 28 09:26:13 2024 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 1490983178744604.5029479323438; Fri, 31 Mar 2017 10:59:38 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6970B7F746; Fri, 31 Mar 2017 17:59:37 +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 D113B17113; Fri, 31 Mar 2017 17:59:36 +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 6904218523C8; Fri, 31 Mar 2017 17:59:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2VHsAEq028365 for ; Fri, 31 Mar 2017 13:54:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 501F917113; Fri, 31 Mar 2017 17:54:10 +0000 (UTC) Received: from mamuti.net (unknown [10.40.205.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CAA4062926 for ; Fri, 31 Mar 2017 17:54:07 +0000 (UTC) Received: by mamuti.net (Postfix, from userid 500) id 9F2C6100699; Fri, 31 Mar 2017 19:54:05 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6970B7F746 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.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 6970B7F746 From: Jiri Denemark To: libvir-list@redhat.com Date: Fri, 31 Mar 2017 19:53:58 +0200 Message-Id: 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.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/7] cpu: Introduce virCPUCopyMigratable 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 31 Mar 2017 17:59:38 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This new internal API makes a copy of virCPUDef while removing all features which would block migration. It uses cpu_map.xml as a database of such features, which should only be used as a fallback when we cannot get the data from a hypervisor. The main goal of this API is to decouple this filtering from virCPUUpdate so that the hypervisor driver can filter the features according to the hypervisor. Signed-off-by: Jiri Denemark --- src/cpu/cpu.c | 29 +++++++++++++++++++++++++++++ src/cpu/cpu.h | 8 ++++++++ src/cpu/cpu_x86.c | 25 +++++++++++++++++++++++++ src/libvirt_private.syms | 1 + 4 files changed, 63 insertions(+) diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 93647a2ed..1cc68f142 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -1130,3 +1130,32 @@ virCPUExpandFeatures(virArch arch, VIR_DEBUG("nfeatures=3D%zu", cpu->nfeatures); return 0; } + + +/** + * virCPUCopyMigratable: + * + * @arch: CPU architecture + * @cpu: CPU definition to be copied + * + * Makes a copy of @cpu with all features which would block migration remo= ved. + * + * Returns the copy of the CPU or NULL on error. + */ +virCPUDefPtr +virCPUCopyMigratable(virArch arch, + virCPUDefPtr cpu) +{ + struct cpuArchDriver *driver; + + VIR_DEBUG("arch=3D%s, cpu=3D%p, model=3D%s", + virArchToString(arch), cpu, NULLSTR(cpu->model)); + + if (!(driver =3D cpuGetSubDriver(arch))) + return NULL; + + if (driver->copyMigratable) + return driver->copyMigratable(cpu); + else + return virCPUDefCopy(cpu); +} diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 8c238ad55..352445c40 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -118,6 +118,9 @@ typedef int typedef int (*virCPUArchExpandFeatures)(virCPUDefPtr cpu); =20 +typedef virCPUDefPtr +(*virCPUArchCopyMigratable)(virCPUDefPtr cpu); + struct cpuArchDriver { const char *name; const virArch *arch; @@ -138,6 +141,7 @@ struct cpuArchDriver { virCPUArchTranslate translate; virCPUArchConvertLegacy convertLegacy; virCPUArchExpandFeatures expandFeatures; + virCPUArchCopyMigratable copyMigratable; }; =20 =20 @@ -254,6 +258,10 @@ int virCPUExpandFeatures(virArch arch, virCPUDefPtr cpu); =20 +virCPUDefPtr +virCPUCopyMigratable(virArch arch, + virCPUDefPtr cpu); + /* virCPUDataFormat and virCPUDataParse are implemented for unit tests onl= y and * have no real-life usage */ diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 48648a7f4..a771b251e 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -2903,6 +2903,30 @@ virCPUx86ExpandFeatures(virCPUDefPtr cpu) } =20 =20 +static virCPUDefPtr +virCPUx86CopyMigratable(virCPUDefPtr cpu) +{ + virCPUDefPtr copy; + virCPUx86MapPtr map; + + if (!(map =3D virCPUx86GetMap())) + return NULL; + + if (!(copy =3D virCPUDefCopyWithoutModel(cpu))) + return NULL; + + if (virCPUDefCopyModelFilter(copy, cpu, false, + x86FeatureIsMigratable, map) < 0) + goto error; + + return copy; + + error: + virCPUDefFree(copy); + return NULL; +} + + int virCPUx86DataAddCPUID(virCPUDataPtr cpuData, const virCPUx86CPUID *cpuid) @@ -2978,4 +3002,5 @@ struct cpuArchDriver cpuDriverX86 =3D { .getModels =3D virCPUx86GetModels, .translate =3D virCPUx86Translate, .expandFeatures =3D virCPUx86ExpandFeatures, + .copyMigratable =3D virCPUx86CopyMigratable, }; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b551cb86a..dc6db3b28 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1016,6 +1016,7 @@ virCPUCheckFeature; virCPUCompare; virCPUCompareXML; virCPUConvertLegacy; +virCPUCopyMigratable; virCPUDataCheckFeature; virCPUDataFormat; virCPUDataFree; --=20 2.12.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list