From 496156807b62bd0b8a27b1fbfd6449db10595cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Thu, 5 Feb 2015 15:28:09 +0100 Subject: [PATCH] Implement VIR_CONNECT_BASELINE_CPU_MIGRATABLE in the x86 cpu driver Filter out non-migratable features if VIR_CONNECT_BASELINE_CPU_MIGRATABLE was specified. --- src/bhyve/bhyve_driver.c | 3 +- src/cpu/cpu_x86.c | 21 ++++++++++- src/qemu/qemu_driver.c | 3 +- tests/cputest.c | 6 +++ .../cputestdata/x86-baseline-6-migratable.xml | 10 +++++ tests/cputestdata/x86-baseline-6-result.xml | 11 ++++++ tests/cputestdata/x86-baseline-6.xml | 37 +++++++++++++++++++ 7 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 tests/cputestdata/x86-baseline-6-migratable.xml create mode 100644 tests/cputestdata/x86-baseline-6-result.xml create mode 100644 tests/cputestdata/x86-baseline-6.xml diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index ae3991773a..2817f8e1c5 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1340,7 +1340,8 @@ bhyveConnectBaselineCPU(virConnectPtr conn, { char *cpu = NULL; - virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, NULL); + virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES | + VIR_CONNECT_BASELINE_CPU_MIGRATABLE, NULL); if (virConnectBaselineCPUEnsureACL(conn) < 0) goto cleanup; diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 45be262307..bf1867bd4d 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1556,7 +1556,8 @@ x86Decode(virCPUDefPtr cpu, const virCPUx86Data *cpuData = NULL; size_t i; - virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, -1); + virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES | + VIR_CONNECT_BASELINE_CPU_MIGRATABLE, -1); if (!data || !(map = virCPUx86GetMap())) return -1; @@ -1633,6 +1634,21 @@ x86Decode(virCPUDefPtr cpu, goto out; } + /* Remove non-migratable features if requested + * Note: this only works as long as no CPU model contains non-migratable + * features directly */ + if (flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE) { + for (i = 0; i < cpuModel->nfeatures; i++) { + const struct x86_feature *feat; + for (feat = map->migrate_blockers; feat; feat = feat->next) { + if (STREQ(feat->name, cpuModel->features[i].name)) { + VIR_FREE(cpuModel->features[i].name); + VIR_DELETE_ELEMENT_INPLACE(cpuModel->features, i, cpuModel->nfeatures); + } + } + } + } + if (flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) { if (!(copy = x86DataCopy(cpuData)) || !(features = x86DataFromCPUFeatures(cpuModel, map))) @@ -1915,6 +1931,9 @@ x86Baseline(virCPUDefPtr *cpus, const char *modelName; bool matchingNames = true; + virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES | + VIR_CONNECT_BASELINE_CPU_MIGRATABLE, NULL); + if (!(map = virCPUx86GetMap())) goto error; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e2824643f0..fc34305645 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12412,7 +12412,8 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED, { char *cpu = NULL; - virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, NULL); + virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES | + VIR_CONNECT_BASELINE_CPU_MIGRATABLE, NULL); if (virConnectBaselineCPUEnsureACL(conn) < 0) goto cleanup; diff --git a/tests/cputest.c b/tests/cputest.c index 76cc9d415a..449b7d1e25 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -346,6 +346,8 @@ cpuTestBaseline(const void *arg) if (data->flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) suffix = "expanded"; + else if (data->flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE) + suffix = "migratable"; else suffix = "result"; if (virAsprintf(&result, "%s-%s", data->name, suffix) < 0) @@ -533,6 +535,8 @@ mymain(void) char *label; \ if ((flags) & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) \ suffix = " (expanded)"; \ + if ((flags) & VIR_CONNECT_BASELINE_CPU_MIGRATABLE) \ + suffix = " (migratable)"; \ if (virAsprintf(&label, "%s%s", name, suffix) < 0) { \ ret = -1; \ } else { \ @@ -612,6 +616,8 @@ mymain(void) DO_TEST_BASELINE("x86", "4", VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, 0); DO_TEST_BASELINE("x86", "5", 0, 0); DO_TEST_BASELINE("x86", "5", VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, 0); + DO_TEST_BASELINE("x86", "6", 0, 0); + DO_TEST_BASELINE("x86", "6", VIR_CONNECT_BASELINE_CPU_MIGRATABLE, 0); DO_TEST_BASELINE("ppc64", "incompatible-vendors", 0, -1); DO_TEST_BASELINE("ppc64", "no-vendor", 0, 0); diff --git a/tests/cputestdata/x86-baseline-6-migratable.xml b/tests/cputestdata/x86-baseline-6-migratable.xml new file mode 100644 index 0000000000..3c2f38c9aa --- /dev/null +++ b/tests/cputestdata/x86-baseline-6-migratable.xml @@ -0,0 +1,10 @@ + + SandyBridge + Intel + + + + + + + diff --git a/tests/cputestdata/x86-baseline-6-result.xml b/tests/cputestdata/x86-baseline-6-result.xml new file mode 100644 index 0000000000..bea0bebf40 --- /dev/null +++ b/tests/cputestdata/x86-baseline-6-result.xml @@ -0,0 +1,11 @@ + + SandyBridge + Intel + + + + + + + + diff --git a/tests/cputestdata/x86-baseline-6.xml b/tests/cputestdata/x86-baseline-6.xml new file mode 100644 index 0000000000..9845b93138 --- /dev/null +++ b/tests/cputestdata/x86-baseline-6.xml @@ -0,0 +1,37 @@ + + + x86_64 + Westmere + Intel + + + + + + + + + + + + + + + x86_64 + Nehalem + Intel + + + + + + + + + + + + + + +