提交 a1adfb0f 编写于 作者: J Jiri Denemark

qemu: Add support for unavailable-features

QEMU 2.8.0 adds support for unavailable-features in
query-cpu-definitions reply. The unavailable-features array lists CPU
features which prevent a corresponding CPU model from being usable on
current host. It can only be used when all the unavailable features are
disabled. Empty array means the CPU model can be used without
modifications.

We can use unavailable-features for providing CPU model usability info
in domain capabilities XML:

    <domainCapabilities>
      ...
      <cpu>
        <mode name='host-passthrough' supported='yes'/>
        <mode name='host-model' supported='yes'>
          <model fallback='allow'>Skylake-Client</model>
          ...
        </mode>
        <mode name='custom' supported='yes'>
          <model usable='yes'>qemu64</model>
          <model usable='yes'>qemu32</model>
          <model usable='no'>phenom</model>
          <model usable='yes'>pentium3</model>
          <model usable='yes'>pentium2</model>
          <model usable='yes'>pentium</model>
          <model usable='yes'>n270</model>
          <model usable='yes'>kvm64</model>
          <model usable='yes'>kvm32</model>
          <model usable='yes'>coreduo</model>
          <model usable='yes'>core2duo</model>
          <model usable='no'>athlon</model>
          <model usable='yes'>Westmere</model>
          <model usable='yes'>Skylake-Client</model>
          ...
        </mode>
      </cpu>
      ...
    </domainCapabilities>
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
上级 fe66e2ff
......@@ -2348,7 +2348,8 @@ int
virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainVirtType type,
const char **name,
size_t count)
size_t count,
virDomainCapsCPUUsable usable)
{
size_t i;
virDomainCapsCPUModelsPtr cpus = NULL;
......@@ -2369,8 +2370,7 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
}
for (i = 0; i < count; i++) {
if (virDomainCapsCPUModelsAdd(cpus, name[i], -1,
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0)
if (virDomainCapsCPUModelsAdd(cpus, name[i], -1, usable) < 0)
return -1;
}
......@@ -2786,9 +2786,14 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
qemuCaps->kvmCPUModels = models;
for (i = 0; i < ncpus; i++) {
if (virDomainCapsCPUModelsAddSteal(models,
&cpus[i]->name,
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0)
virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
if (cpus[i]->usable == VIR_TRISTATE_BOOL_YES)
usable = VIR_DOMCAPS_CPU_USABLE_YES;
else if (cpus[i]->usable == VIR_TRISTATE_BOOL_NO)
usable = VIR_DOMCAPS_CPU_USABLE_NO;
if (virDomainCapsCPUModelsAddSteal(models, &cpus[i]->name, usable) < 0)
goto cleanup;
}
......@@ -3099,14 +3104,23 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
qemuCaps->tcgCPUModels = cpus;
for (i = 0; i < n; i++) {
int usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
if ((str = virXMLPropString(nodes[i], "usable")) &&
(usable = virDomainCapsCPUUsableTypeFromString(str)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown value '%s' in attribute 'usable'"), str);
goto cleanup;
}
VIR_FREE(str);
if (!(str = virXMLPropString(nodes[i], "name"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing cpu name in QEMU capabilities cache"));
goto cleanup;
}
if (virDomainCapsCPUModelsAddSteal(cpus, &str,
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0)
if (virDomainCapsCPUModelsAddSteal(cpus, &str, usable) < 0)
goto cleanup;
}
......@@ -3385,8 +3399,15 @@ virQEMUCapsFormatCPUModels(virQEMUCapsPtr qemuCaps,
return;
for (i = 0; i < cpus->nmodels; i++) {
virDomainCapsCPUModelPtr cpu = cpus->models + i;
virBufferAsprintf(buf, "<cpu type='%s' ", typeStr);
virBufferEscapeString(buf, "name='%s'/>\n", cpus->models[i].name);
virBufferEscapeString(buf, "name='%s'", cpu->name);
if (cpu->usable) {
virBufferAsprintf(buf, " usable='%s'",
virDomainCapsCPUUsableTypeToString(cpu->usable));
}
virBufferAddLit(buf, "/>\n");
}
}
......
......@@ -433,7 +433,8 @@ unsigned int virQEMUCapsGetKVMVersion(virQEMUCapsPtr qemuCaps);
int virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainVirtType type,
const char **name,
size_t count);
size_t count,
virDomainCapsCPUUsable usable);
int virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainVirtType type,
char ***names,
......
......@@ -916,6 +916,7 @@ typedef struct _qemuMonitorCPUDefInfo qemuMonitorCPUDefInfo;
typedef qemuMonitorCPUDefInfo *qemuMonitorCPUDefInfoPtr;
struct _qemuMonitorCPUDefInfo {
virTristateBool usable;
char *name;
};
......
......@@ -4916,6 +4916,24 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
if (VIR_STRDUP(cpu->name, tmp) < 0)
goto cleanup;
if (virJSONValueObjectHasKey(child, "unavailable-features")) {
virJSONValuePtr blockers;
blockers = virJSONValueObjectGetArray(child,
"unavailable-features");
if (!blockers) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("unavailable-features in query-cpu-definitions "
"reply data was not an array"));
goto cleanup;
}
if (virJSONValueArraySize(blockers) > 0)
cpu->usable = VIR_TRISTATE_BOOL_NO;
else
cpu->usable = VIR_TRISTATE_BOOL_YES;
}
}
ret = n;
......
......@@ -24,35 +24,35 @@
<model fallback='allow'>Broadwell</model>
</mode>
<mode name='custom' supported='yes'>
<model usable='unknown'>qemu64</model>
<model usable='unknown'>qemu32</model>
<model usable='unknown'>phenom</model>
<model usable='unknown'>pentium3</model>
<model usable='unknown'>pentium2</model>
<model usable='unknown'>pentium</model>
<model usable='unknown'>n270</model>
<model usable='unknown'>kvm64</model>
<model usable='unknown'>kvm32</model>
<model usable='unknown'>coreduo</model>
<model usable='unknown'>core2duo</model>
<model usable='unknown'>athlon</model>
<model usable='unknown'>Westmere</model>
<model usable='unknown'>Skylake-Client</model>
<model usable='unknown'>SandyBridge</model>
<model usable='unknown'>Penryn</model>
<model usable='unknown'>Opteron_G5</model>
<model usable='unknown'>Opteron_G4</model>
<model usable='unknown'>Opteron_G3</model>
<model usable='unknown'>Opteron_G2</model>
<model usable='unknown'>Opteron_G1</model>
<model usable='unknown'>Nehalem</model>
<model usable='unknown'>IvyBridge</model>
<model usable='unknown'>Haswell</model>
<model usable='unknown'>Haswell-noTSX</model>
<model usable='unknown'>Conroe</model>
<model usable='unknown'>Broadwell</model>
<model usable='unknown'>Broadwell-noTSX</model>
<model usable='unknown'>486</model>
<model usable='yes'>qemu64</model>
<model usable='yes'>qemu32</model>
<model usable='no'>phenom</model>
<model usable='yes'>pentium3</model>
<model usable='yes'>pentium2</model>
<model usable='yes'>pentium</model>
<model usable='yes'>n270</model>
<model usable='yes'>kvm64</model>
<model usable='yes'>kvm32</model>
<model usable='yes'>coreduo</model>
<model usable='yes'>core2duo</model>
<model usable='yes'>athlon</model>
<model usable='yes'>Westmere</model>
<model usable='no'>Skylake-Client</model>
<model usable='no'>SandyBridge</model>
<model usable='yes'>Penryn</model>
<model usable='no'>Opteron_G5</model>
<model usable='no'>Opteron_G4</model>
<model usable='no'>Opteron_G3</model>
<model usable='yes'>Opteron_G2</model>
<model usable='yes'>Opteron_G1</model>
<model usable='yes'>Nehalem</model>
<model usable='no'>IvyBridge</model>
<model usable='no'>Haswell</model>
<model usable='no'>Haswell-noTSX</model>
<model usable='yes'>Conroe</model>
<model usable='no'>Broadwell</model>
<model usable='no'>Broadwell-noTSX</model>
<model usable='yes'>486</model>
</mode>
</cpu>
<devices>
......
......@@ -24,35 +24,35 @@
<model fallback='allow'>Broadwell</model>
</mode>
<mode name='custom' supported='yes'>
<model usable='unknown'>qemu64</model>
<model usable='unknown'>qemu32</model>
<model usable='unknown'>phenom</model>
<model usable='unknown'>pentium3</model>
<model usable='unknown'>pentium2</model>
<model usable='unknown'>pentium</model>
<model usable='unknown'>n270</model>
<model usable='unknown'>kvm64</model>
<model usable='unknown'>kvm32</model>
<model usable='unknown'>coreduo</model>
<model usable='unknown'>core2duo</model>
<model usable='unknown'>athlon</model>
<model usable='unknown'>Westmere</model>
<model usable='unknown'>Skylake-Client</model>
<model usable='unknown'>SandyBridge</model>
<model usable='unknown'>Penryn</model>
<model usable='unknown'>Opteron_G5</model>
<model usable='unknown'>Opteron_G4</model>
<model usable='unknown'>Opteron_G3</model>
<model usable='unknown'>Opteron_G2</model>
<model usable='unknown'>Opteron_G1</model>
<model usable='unknown'>Nehalem</model>
<model usable='unknown'>IvyBridge</model>
<model usable='unknown'>Haswell</model>
<model usable='unknown'>Haswell-noTSX</model>
<model usable='unknown'>Conroe</model>
<model usable='unknown'>Broadwell</model>
<model usable='unknown'>Broadwell-noTSX</model>
<model usable='unknown'>486</model>
<model usable='yes'>qemu64</model>
<model usable='yes'>qemu32</model>
<model usable='no'>phenom</model>
<model usable='yes'>pentium3</model>
<model usable='yes'>pentium2</model>
<model usable='yes'>pentium</model>
<model usable='yes'>n270</model>
<model usable='yes'>kvm64</model>
<model usable='yes'>kvm32</model>
<model usable='yes'>coreduo</model>
<model usable='yes'>core2duo</model>
<model usable='no'>athlon</model>
<model usable='yes'>Westmere</model>
<model usable='yes'>Skylake-Client</model>
<model usable='yes'>SandyBridge</model>
<model usable='yes'>Penryn</model>
<model usable='no'>Opteron_G5</model>
<model usable='no'>Opteron_G4</model>
<model usable='no'>Opteron_G3</model>
<model usable='yes'>Opteron_G2</model>
<model usable='yes'>Opteron_G1</model>
<model usable='yes'>Nehalem</model>
<model usable='yes'>IvyBridge</model>
<model usable='yes'>Haswell</model>
<model usable='yes'>Haswell-noTSX</model>
<model usable='yes'>Conroe</model>
<model usable='yes'>Broadwell</model>
<model usable='yes'>Broadwell-noTSX</model>
<model usable='yes'>486</model>
</mode>
</cpu>
<devices>
......
......@@ -200,66 +200,66 @@
<kvmVersion>0</kvmVersion>
<package> (v2.8.0-rc1-dirty)</package>
<arch>x86_64</arch>
<cpu type='kvm' name='host'/>
<cpu type='kvm' name='qemu64'/>
<cpu type='kvm' name='qemu32'/>
<cpu type='kvm' name='phenom'/>
<cpu type='kvm' name='pentium3'/>
<cpu type='kvm' name='pentium2'/>
<cpu type='kvm' name='pentium'/>
<cpu type='kvm' name='n270'/>
<cpu type='kvm' name='kvm64'/>
<cpu type='kvm' name='kvm32'/>
<cpu type='kvm' name='coreduo'/>
<cpu type='kvm' name='core2duo'/>
<cpu type='kvm' name='athlon'/>
<cpu type='kvm' name='Westmere'/>
<cpu type='kvm' name='Skylake-Client'/>
<cpu type='kvm' name='SandyBridge'/>
<cpu type='kvm' name='Penryn'/>
<cpu type='kvm' name='Opteron_G5'/>
<cpu type='kvm' name='Opteron_G4'/>
<cpu type='kvm' name='Opteron_G3'/>
<cpu type='kvm' name='Opteron_G2'/>
<cpu type='kvm' name='Opteron_G1'/>
<cpu type='kvm' name='Nehalem'/>
<cpu type='kvm' name='IvyBridge'/>
<cpu type='kvm' name='Haswell'/>
<cpu type='kvm' name='Haswell-noTSX'/>
<cpu type='kvm' name='Conroe'/>
<cpu type='kvm' name='Broadwell'/>
<cpu type='kvm' name='Broadwell-noTSX'/>
<cpu type='kvm' name='486'/>
<cpu type='tcg' name='host'/>
<cpu type='tcg' name='qemu64'/>
<cpu type='tcg' name='qemu32'/>
<cpu type='tcg' name='phenom'/>
<cpu type='tcg' name='pentium3'/>
<cpu type='tcg' name='pentium2'/>
<cpu type='tcg' name='pentium'/>
<cpu type='tcg' name='n270'/>
<cpu type='tcg' name='kvm64'/>
<cpu type='tcg' name='kvm32'/>
<cpu type='tcg' name='coreduo'/>
<cpu type='tcg' name='core2duo'/>
<cpu type='tcg' name='athlon'/>
<cpu type='tcg' name='Westmere'/>
<cpu type='tcg' name='Skylake-Client'/>
<cpu type='tcg' name='SandyBridge'/>
<cpu type='tcg' name='Penryn'/>
<cpu type='tcg' name='Opteron_G5'/>
<cpu type='tcg' name='Opteron_G4'/>
<cpu type='tcg' name='Opteron_G3'/>
<cpu type='tcg' name='Opteron_G2'/>
<cpu type='tcg' name='Opteron_G1'/>
<cpu type='tcg' name='Nehalem'/>
<cpu type='tcg' name='IvyBridge'/>
<cpu type='tcg' name='Haswell'/>
<cpu type='tcg' name='Haswell-noTSX'/>
<cpu type='tcg' name='Conroe'/>
<cpu type='tcg' name='Broadwell'/>
<cpu type='tcg' name='Broadwell-noTSX'/>
<cpu type='tcg' name='486'/>
<cpu type='kvm' name='host' usable='yes'/>
<cpu type='kvm' name='qemu64' usable='yes'/>
<cpu type='kvm' name='qemu32' usable='yes'/>
<cpu type='kvm' name='phenom' usable='no'/>
<cpu type='kvm' name='pentium3' usable='yes'/>
<cpu type='kvm' name='pentium2' usable='yes'/>
<cpu type='kvm' name='pentium' usable='yes'/>
<cpu type='kvm' name='n270' usable='yes'/>
<cpu type='kvm' name='kvm64' usable='yes'/>
<cpu type='kvm' name='kvm32' usable='yes'/>
<cpu type='kvm' name='coreduo' usable='yes'/>
<cpu type='kvm' name='core2duo' usable='yes'/>
<cpu type='kvm' name='athlon' usable='no'/>
<cpu type='kvm' name='Westmere' usable='yes'/>
<cpu type='kvm' name='Skylake-Client' usable='yes'/>
<cpu type='kvm' name='SandyBridge' usable='yes'/>
<cpu type='kvm' name='Penryn' usable='yes'/>
<cpu type='kvm' name='Opteron_G5' usable='no'/>
<cpu type='kvm' name='Opteron_G4' usable='no'/>
<cpu type='kvm' name='Opteron_G3' usable='no'/>
<cpu type='kvm' name='Opteron_G2' usable='yes'/>
<cpu type='kvm' name='Opteron_G1' usable='yes'/>
<cpu type='kvm' name='Nehalem' usable='yes'/>
<cpu type='kvm' name='IvyBridge' usable='yes'/>
<cpu type='kvm' name='Haswell' usable='yes'/>
<cpu type='kvm' name='Haswell-noTSX' usable='yes'/>
<cpu type='kvm' name='Conroe' usable='yes'/>
<cpu type='kvm' name='Broadwell' usable='yes'/>
<cpu type='kvm' name='Broadwell-noTSX' usable='yes'/>
<cpu type='kvm' name='486' usable='yes'/>
<cpu type='tcg' name='host' usable='no'/>
<cpu type='tcg' name='qemu64' usable='yes'/>
<cpu type='tcg' name='qemu32' usable='yes'/>
<cpu type='tcg' name='phenom' usable='no'/>
<cpu type='tcg' name='pentium3' usable='yes'/>
<cpu type='tcg' name='pentium2' usable='yes'/>
<cpu type='tcg' name='pentium' usable='yes'/>
<cpu type='tcg' name='n270' usable='yes'/>
<cpu type='tcg' name='kvm64' usable='yes'/>
<cpu type='tcg' name='kvm32' usable='yes'/>
<cpu type='tcg' name='coreduo' usable='yes'/>
<cpu type='tcg' name='core2duo' usable='yes'/>
<cpu type='tcg' name='athlon' usable='yes'/>
<cpu type='tcg' name='Westmere' usable='yes'/>
<cpu type='tcg' name='Skylake-Client' usable='no'/>
<cpu type='tcg' name='SandyBridge' usable='no'/>
<cpu type='tcg' name='Penryn' usable='yes'/>
<cpu type='tcg' name='Opteron_G5' usable='no'/>
<cpu type='tcg' name='Opteron_G4' usable='no'/>
<cpu type='tcg' name='Opteron_G3' usable='no'/>
<cpu type='tcg' name='Opteron_G2' usable='yes'/>
<cpu type='tcg' name='Opteron_G1' usable='yes'/>
<cpu type='tcg' name='Nehalem' usable='yes'/>
<cpu type='tcg' name='IvyBridge' usable='no'/>
<cpu type='tcg' name='Haswell' usable='no'/>
<cpu type='tcg' name='Haswell-noTSX' usable='no'/>
<cpu type='tcg' name='Conroe' usable='yes'/>
<cpu type='tcg' name='Broadwell' usable='no'/>
<cpu type='tcg' name='Broadwell-noTSX' usable='no'/>
<cpu type='tcg' name='486' usable='yes'/>
<machine name='pc-i440fx-2.8' alias='pc' hotplugCpus='yes' maxCpus='255'/>
<machine name='pc-0.12' hotplugCpus='yes' maxCpus='255'/>
<machine name='pc-i440fx-2.4' hotplugCpus='yes' maxCpus='255'/>
......
......@@ -432,10 +432,12 @@ testQemuMonitorJSONGetCPUDefinitions(const void *data)
" \"name\": \"qemu64\" "
" }, "
" { "
" \"name\": \"Opteron_G4\" "
" \"name\": \"Opteron_G4\", "
" \"unavailable-features\": [\"vme\"]"
" }, "
" { "
" \"name\": \"Westmere\" "
" \"name\": \"Westmere\", "
" \"unavailable-features\": []"
" } "
" ]"
"}") < 0)
......@@ -451,7 +453,7 @@ testQemuMonitorJSONGetCPUDefinitions(const void *data)
goto cleanup;
}
#define CHECK(i, wantname) \
#define CHECK_FULL(i, wantname, Usable) \
do { \
if (STRNEQ(cpus[i]->name, (wantname))) { \
virReportError(VIR_ERR_INTERNAL_ERROR, \
......@@ -459,13 +461,28 @@ testQemuMonitorJSONGetCPUDefinitions(const void *data)
cpus[i]->name, (wantname)); \
goto cleanup; \
} \
if (cpus[i]->usable != (Usable)) { \
virReportError(VIR_ERR_INTERNAL_ERROR, \
"%s: expecting usable flag %d, got %d", \
cpus[i]->name, Usable, cpus[i]->usable); \
goto cleanup; \
} \
} while (0)
#define CHECK(i, wantname) \
CHECK_FULL(i, wantname, VIR_TRISTATE_BOOL_ABSENT)
#define CHECK_USABLE(i, wantname, usable) \
CHECK_FULL(i, wantname, \
usable ? VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO)
CHECK(0, "qemu64");
CHECK(1, "Opteron_G4");
CHECK(2, "Westmere");
CHECK_USABLE(1, "Opteron_G4", false);
CHECK_USABLE(2, "Westmere", true);
#undef CHECK
#undef CHECK_USABLE
#undef CHECK_FULL
ret = 0;
......
......@@ -303,31 +303,39 @@ testAddCPUModels(virQEMUCapsPtr caps, bool skipLegacy)
if (ARCH_IS_X86(arch)) {
if (virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_KVM, x86Models,
ARRAY_CARDINALITY(x86Models)) < 0 ||
ARRAY_CARDINALITY(x86Models),
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0 ||
virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_QEMU, x86Models,
ARRAY_CARDINALITY(x86Models)) < 0)
ARRAY_CARDINALITY(x86Models),
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0)
return -1;
if (!skipLegacy) {
if (virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_KVM,
x86LegacyModels,
ARRAY_CARDINALITY(x86LegacyModels)) < 0 ||
ARRAY_CARDINALITY(x86LegacyModels),
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0 ||
virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_QEMU,
x86LegacyModels,
ARRAY_CARDINALITY(x86LegacyModels)) < 0)
ARRAY_CARDINALITY(x86LegacyModels),
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0)
return -1;
}
} else if (ARCH_IS_ARM(arch)) {
if (virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_KVM, armModels,
ARRAY_CARDINALITY(armModels)) < 0 ||
ARRAY_CARDINALITY(armModels),
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0 ||
virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_QEMU, armModels,
ARRAY_CARDINALITY(armModels)) < 0)
ARRAY_CARDINALITY(armModels),
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0)
return -1;
} else if (ARCH_IS_PPC64(arch)) {
if (virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_KVM, ppc64Models,
ARRAY_CARDINALITY(ppc64Models)) < 0 ||
ARRAY_CARDINALITY(ppc64Models),
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0 ||
virQEMUCapsAddCPUDefinitions(caps, VIR_DOMAIN_VIRT_QEMU, ppc64Models,
ARRAY_CARDINALITY(ppc64Models)) < 0)
ARRAY_CARDINALITY(ppc64Models),
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0)
return -1;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册