提交 61ee757e 编写于 作者: J Jiri Denemark

qemu: Add APIs for translating CPU features

So far we always used libvirt's name of each CPU feature relying on
backward compatible aliases in QEMU. The new translation table can be
used whenever QEMU mandates or prefers canonical feature names.
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 24aa210d
...@@ -2848,6 +2848,70 @@ virQEMUCapsCPUFilterFeatures(const char *name, ...@@ -2848,6 +2848,70 @@ virQEMUCapsCPUFilterFeatures(const char *name,
} }
typedef struct _virQEMUCapsCPUFeatureTranslationTable virQEMUCapsCPUFeatureTranslationTable;
typedef virQEMUCapsCPUFeatureTranslationTable *virQEMUCapsCPUFeatureTranslationTablePtr;
struct _virQEMUCapsCPUFeatureTranslationTable {
const char *libvirt;
const char *qemu;
};
virQEMUCapsCPUFeatureTranslationTable virQEMUCapsCPUFeaturesX86[] = {
{"cmp_legacy", "cmp-legacy"},
{"ds_cpl", "ds-cpl"},
{"fxsr_opt", "fxsr-opt"},
{"kvm_pv_eoi", "kvm-pv-eoi"},
{"kvm_pv_unhalt", "kvm-pv-unhalt"},
{"lahf_lm", "lahf-lm"},
{"nodeid_msr", "nodeid-msr"},
{"pclmuldq", "pclmulqdq"},
{"perfctr_core", "perfctr-core"},
{"perfctr_nb", "perfctr-nb"},
{"tsc_adjust", "tsc-adjust"},
{NULL, NULL}
};
static const char *
virQEMUCapsCPUFeatureTranslate(virQEMUCapsPtr qemuCaps,
const char *feature,
bool reversed)
{
virQEMUCapsCPUFeatureTranslationTablePtr table = NULL;
virQEMUCapsCPUFeatureTranslationTablePtr entry;
if (ARCH_IS_X86(qemuCaps->arch))
table = virQEMUCapsCPUFeaturesX86;
if (!table || !feature)
return feature;
for (entry = table; entry->libvirt; entry++) {
const char *key = reversed ? entry->qemu : entry->libvirt;
if (STREQ(feature, key))
return reversed ? entry->libvirt : entry->qemu;
}
return feature;
}
const char *
virQEMUCapsCPUFeatureToQEMU(virQEMUCapsPtr qemuCaps,
const char *feature)
{
return virQEMUCapsCPUFeatureTranslate(qemuCaps, feature, false);
}
const char *
virQEMUCapsCPUFeatureFromQEMU(virQEMUCapsPtr qemuCaps,
const char *feature)
{
return virQEMUCapsCPUFeatureTranslate(qemuCaps, feature, true);
}
/** /**
* Returns 0 when host CPU model provided by QEMU was filled in qemuCaps, * Returns 0 when host CPU model provided by QEMU was filled in qemuCaps,
* 1 when the caller should fall back to using virCapsPtr->host.cpu, * 1 when the caller should fall back to using virCapsPtr->host.cpu,
......
...@@ -645,6 +645,14 @@ bool virQEMUCapsGuestIsNative(virArch host, ...@@ -645,6 +645,14 @@ bool virQEMUCapsGuestIsNative(virArch host,
bool virQEMUCapsCPUFilterFeatures(const char *name, bool virQEMUCapsCPUFilterFeatures(const char *name,
void *opaque); void *opaque);
const char *
virQEMUCapsCPUFeatureToQEMU(virQEMUCapsPtr qemuCaps,
const char *feature);
const char *
virQEMUCapsCPUFeatureFromQEMU(virQEMUCapsPtr qemuCaps,
const char *feature);
virSEVCapabilityPtr virSEVCapabilityPtr
virQEMUCapsGetSEVCapabilities(virQEMUCapsPtr qemuCaps); virQEMUCapsGetSEVCapabilities(virQEMUCapsPtr qemuCaps);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册