The only part of qemuCaps both functions are interested in is the CPU
architecture. Changing them to expect just virArch makes the functions
more reusable.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
---
Notes:
Version 2:
- no change
src/qemu/qemu_capabilities.c | 18 +++++++++---------
src/qemu/qemu_capabilities.h | 4 ++--
src/qemu/qemu_command.c | 2 +-
src/qemu/qemu_monitor.c | 7 +++----
src/qemu/qemu_monitor.h | 5 ++---
src/qemu/qemu_monitor_json.c | 11 ++++-------
src/qemu/qemu_monitor_json.h | 1 -
src/qemu/qemu_process.c | 12 +-----------
8 files changed, 22 insertions(+), 38 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index c12e6dac69..f366e6797c 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3108,7 +3108,7 @@ virQEMUCapsGetCPUFeatures(virQEMUCaps *qemuCaps,
if (migratable && prop->migratable == VIR_TRISTATE_BOOL_NO)
continue;
- list[n++] = g_strdup(virQEMUCapsCPUFeatureFromQEMU(qemuCaps, prop->name));
+ list[n++] = g_strdup(virQEMUCapsCPUFeatureFromQEMU(qemuCaps->arch,
prop->name));
}
*features = g_steal_pointer(&list);
@@ -3434,14 +3434,14 @@ virQEMUCapsCPUFeatureTranslationTable virQEMUCapsCPUFeaturesX86[]
= {
static const char *
-virQEMUCapsCPUFeatureTranslate(virQEMUCaps *qemuCaps,
+virQEMUCapsCPUFeatureTranslate(virArch arch,
const char *feature,
bool reversed)
{
virQEMUCapsCPUFeatureTranslationTable *table = NULL;
virQEMUCapsCPUFeatureTranslationTable *entry;
- if (ARCH_IS_X86(qemuCaps->arch))
+ if (ARCH_IS_X86(arch))
table = virQEMUCapsCPUFeaturesX86;
if (!table ||
@@ -3460,18 +3460,18 @@ virQEMUCapsCPUFeatureTranslate(virQEMUCaps *qemuCaps,
const char *
-virQEMUCapsCPUFeatureToQEMU(virQEMUCaps *qemuCaps,
+virQEMUCapsCPUFeatureToQEMU(virArch arch,
const char *feature)
{
- return virQEMUCapsCPUFeatureTranslate(qemuCaps, feature, false);
+ return virQEMUCapsCPUFeatureTranslate(arch, feature, false);
}
const char *
-virQEMUCapsCPUFeatureFromQEMU(virQEMUCaps *qemuCaps,
+virQEMUCapsCPUFeatureFromQEMU(virArch arch,
const char *feature)
{
- return virQEMUCapsCPUFeatureTranslate(qemuCaps, feature, true);
+ return virQEMUCapsCPUFeatureTranslate(arch, feature, true);
}
@@ -3510,7 +3510,7 @@ virQEMUCapsInitCPUModelS390(virQEMUCaps *qemuCaps,
for (i = 0; i < modelInfo->nprops; i++) {
virCPUFeatureDef *feature = cpu->features + cpu->nfeatures;
qemuMonitorCPUProperty *prop = modelInfo->props + i;
- const char *name = virQEMUCapsCPUFeatureFromQEMU(qemuCaps, prop->name);
+ const char *name = virQEMUCapsCPUFeatureFromQEMU(qemuCaps->arch,
prop->name);
if (prop->type != QEMU_MONITOR_CPU_PROPERTY_BOOLEAN)
continue;
@@ -3545,7 +3545,7 @@ virQEMUCapsGetCPUModelX86Data(virQEMUCaps *qemuCaps,
for (i = 0; i < model->nprops; i++) {
qemuMonitorCPUProperty *prop = model->props + i;
- const char *name = virQEMUCapsCPUFeatureFromQEMU(qemuCaps, prop->name);
+ const char *name = virQEMUCapsCPUFeatureFromQEMU(qemuCaps->arch,
prop->name);
switch (prop->type) {
case QEMU_MONITOR_CPU_PROPERTY_BOOLEAN:
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index ca919ff368..904ee54f60 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -838,11 +838,11 @@ bool virQEMUCapsCPUFilterFeatures(const char *name,
void *opaque);
const char *
-virQEMUCapsCPUFeatureToQEMU(virQEMUCaps *qemuCaps,
+virQEMUCapsCPUFeatureToQEMU(virArch arch,
const char *feature);
const char *
-virQEMUCapsCPUFeatureFromQEMU(virQEMUCaps *qemuCaps,
+virQEMUCapsCPUFeatureFromQEMU(virArch arch,
const char *feature);
virSEVCapability *
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7ec44736d3..150824f2e1 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6111,7 +6111,7 @@ qemuBuildCpuModelArgStr(virQEMUDriver *driver,
for (i = 0; i < cpu->nfeatures; i++) {
const char *featname =
- virQEMUCapsCPUFeatureToQEMU(qemuCaps, cpu->features[i].name);
+ virQEMUCapsCPUFeatureToQEMU(def->os.arch, cpu->features[i].name);
switch ((virCPUFeaturePolicy) cpu->features[i].policy) {
case VIR_CPU_FEATURE_FORCE:
case VIR_CPU_FEATURE_REQUIRE:
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index c2808c75a3..5eba154d96 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3633,12 +3633,11 @@ qemuMonitorGetGuestCPU(qemuMonitor *mon,
virArch arch,
const char *cpuQOMPath,
qemuMonitorCPUFeatureTranslationCallback translate,
- void *opaque,
virCPUData **enabled,
virCPUData **disabled)
{
- VIR_DEBUG("arch=%s cpuQOMPath=%s translate=%p opaque=%p enabled=%p
disabled=%p",
- virArchToString(arch), cpuQOMPath, translate, opaque, enabled, disabled);
+ VIR_DEBUG("arch=%s cpuQOMPath=%s translate=%p enabled=%p disabled=%p",
+ virArchToString(arch), cpuQOMPath, translate, enabled, disabled);
QEMU_CHECK_MONITOR(mon);
@@ -3646,7 +3645,7 @@ qemuMonitorGetGuestCPU(qemuMonitor *mon,
if (disabled)
*disabled = NULL;
- return qemuMonitorJSONGetGuestCPU(mon, arch, cpuQOMPath, translate, opaque,
+ return qemuMonitorJSONGetGuestCPU(mon, arch, cpuQOMPath, translate,
enabled, disabled);
}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 4d770486be..4fead0a998 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1219,14 +1219,13 @@ int qemuMonitorGetGuestCPUx86(qemuMonitor *mon,
virCPUData **data,
virCPUData **disabled);
-typedef const char *(*qemuMonitorCPUFeatureTranslationCallback)(const char *name,
- void *opaque);
+typedef const char *(*qemuMonitorCPUFeatureTranslationCallback)(virArch arch,
+ const char *name);
int qemuMonitorGetGuestCPU(qemuMonitor *mon,
virArch arch,
const char *cpuQOMPath,
qemuMonitorCPUFeatureTranslationCallback translate,
- void *opaque,
virCPUData **enabled,
virCPUData **disabled);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index b63400354b..f54b4609a9 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6781,7 +6781,6 @@ static int
qemuMonitorJSONGetCPUData(qemuMonitor *mon,
const char *cpuQOMPath,
qemuMonitorCPUFeatureTranslationCallback translate,
- void *opaque,
virCPUData *data)
{
qemuMonitorJSONObjectProperty prop = { .type = QEMU_MONITOR_OBJECT_PROPERTY_BOOLEAN
};
@@ -6801,7 +6800,7 @@ qemuMonitorJSONGetCPUData(qemuMonitor *mon,
continue;
if (translate)
- name = translate(name, opaque);
+ name = translate(data->arch, name);
if (virCPUDataAddFeature(data, name) < 0)
return -1;
@@ -6815,7 +6814,6 @@ static int
qemuMonitorJSONGetCPUDataDisabled(qemuMonitor *mon,
const char *cpuQOMPath,
qemuMonitorCPUFeatureTranslationCallback translate,
- void *opaque,
virCPUData *data)
{
g_auto(GStrv) props = NULL;
@@ -6829,7 +6827,7 @@ qemuMonitorJSONGetCPUDataDisabled(qemuMonitor *mon,
const char *name = *p;
if (translate)
- name = translate(name, opaque);
+ name = translate(data->arch, name);
if (virCPUDataAddFeature(data, name) < 0)
return -1;
@@ -6859,7 +6857,6 @@ qemuMonitorJSONGetGuestCPU(qemuMonitor *mon,
virArch arch,
const char *cpuQOMPath,
qemuMonitorCPUFeatureTranslationCallback translate,
- void *opaque,
virCPUData **enabled,
virCPUData **disabled)
{
@@ -6870,11 +6867,11 @@ qemuMonitorJSONGetGuestCPU(qemuMonitor *mon,
!(cpuDisabled = virCPUDataNew(arch)))
return -1;
- if (qemuMonitorJSONGetCPUData(mon, cpuQOMPath, translate, opaque, cpuEnabled) <
0)
+ if (qemuMonitorJSONGetCPUData(mon, cpuQOMPath, translate, cpuEnabled) < 0)
return -1;
if (disabled &&
- qemuMonitorJSONGetCPUDataDisabled(mon, cpuQOMPath, translate, opaque,
cpuDisabled) < 0)
+ qemuMonitorJSONGetCPUDataDisabled(mon, cpuQOMPath, translate, cpuDisabled) <
0)
return -1;
*enabled = g_steal_pointer(&cpuEnabled);
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index a53e6423df..f14d0b5bae 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -605,7 +605,6 @@ qemuMonitorJSONGetGuestCPU(qemuMonitor *mon,
virArch arch,
const char *cpuQOMPath,
qemuMonitorCPUFeatureTranslationCallback translate,
- void *opaque,
virCPUData **enabled,
virCPUData **disabled);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index cec4a64526..d78e91efed 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4295,16 +4295,6 @@ qemuProcessVerifyCPUFeatures(virDomainDef *def,
}
-static const char *
-qemuProcessTranslateCPUFeatures(const char *name,
- void *opaque)
-{
- virQEMUCaps *qemuCaps = opaque;
-
- return virQEMUCapsCPUFeatureFromQEMU(qemuCaps, name);
-}
-
-
/* returns the QOM path to the first vcpu */
static const char *
qemuProcessGetVCPUQOMPath(virDomainObj *vm)
@@ -4349,7 +4339,7 @@ qemuProcessFetchGuestCPU(virDomainObj *vm,
rc = qemuMonitorGetGuestCPU(priv->mon,
vm->def->os.arch,
cpuQOMPath,
- qemuProcessTranslateCPUFeatures, priv->qemuCaps,
+ virQEMUCapsCPUFeatureFromQEMU,
&dataEnabled, &dataDisabled);
} else {
rc = qemuMonitorGetGuestCPUx86(priv->mon, cpuQOMPath, &dataEnabled,
&dataDisabled);
--
2.38.0