Let's store qemuMonitorCPUDefInfo directly in the array of CPUs in
qemuMonitorCPUDefs rather then using an array of pointers.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
---
Notes:
Version 2:
- trivial rebase
src/qemu/qemu_capabilities.c | 14 +++++++-------
src/qemu/qemu_monitor.c | 5 ++---
src/qemu/qemu_monitor.h | 2 +-
src/qemu/qemu_monitor_json.c | 7 +------
tests/qemumonitorjsontest.c | 8 ++++----
5 files changed, 15 insertions(+), 21 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 59af3ab6d3..442445aad9 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2483,11 +2483,11 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
for (name = libvirtModels; name && *name; name++) {
for (i = 0; i < defs->ncpus; i++) {
- if (STRCASENEQ(defs->cpus[i]->name, *name))
+ if (STRCASENEQ(defs->cpus[i].name, *name))
continue;
- VIR_FREE(defs->cpus[i]->name);
- if (VIR_STRDUP(defs->cpus[i]->name, *name) < 0)
+ VIR_FREE(defs->cpus[i].name);
+ if (VIR_STRDUP(defs->cpus[i].name, *name) < 0)
goto cleanup;
}
}
@@ -2499,13 +2499,13 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
for (i = 0; i < defs->ncpus; i++) {
virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
- if (defs->cpus[i]->usable == VIR_TRISTATE_BOOL_YES)
+ if (defs->cpus[i].usable == VIR_TRISTATE_BOOL_YES)
usable = VIR_DOMCAPS_CPU_USABLE_YES;
- else if (defs->cpus[i]->usable == VIR_TRISTATE_BOOL_NO)
+ else if (defs->cpus[i].usable == VIR_TRISTATE_BOOL_NO)
usable = VIR_DOMCAPS_CPU_USABLE_NO;
- if (virDomainCapsCPUModelsAddSteal(models, &defs->cpus[i]->name,
usable,
- &defs->cpus[i]->blockers) < 0)
+ if (virDomainCapsCPUModelsAddSteal(models, &defs->cpus[i].name, usable,
+ &defs->cpus[i].blockers) < 0)
goto cleanup;
}
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index d17387d27f..87a9d06d45 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3557,9 +3557,8 @@ qemuMonitorCPUDefsFree(qemuMonitorCPUDefsPtr defs)
return;
for (i = 0; i < defs->ncpus; i++) {
- virStringListFree(defs->cpus[i]->blockers);
- VIR_FREE(defs->cpus[i]->name);
- VIR_FREE(defs->cpus[i]);
+ virStringListFree(defs->cpus[i].blockers);
+ VIR_FREE(defs->cpus[i].name);
}
VIR_FREE(defs->cpus);
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 359bbfca7f..aa2a0e392a 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1105,7 +1105,7 @@ typedef struct _qemuMonitorCPUDefs qemuMonitorCPUDefs;
typedef qemuMonitorCPUDefs *qemuMonitorCPUDefsPtr;
struct _qemuMonitorCPUDefs {
size_t ncpus;
- qemuMonitorCPUDefInfoPtr *cpus;
+ qemuMonitorCPUDefInfoPtr cpus;
};
int qemuMonitorGetCPUDefinitions(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 664f1b225e..de75c46dc1 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5560,12 +5560,7 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
for (i = 0; i < defs->ncpus; i++) {
virJSONValuePtr child = virJSONValueArrayGet(data, i);
const char *tmp;
- qemuMonitorCPUDefInfoPtr cpu;
-
- if (VIR_ALLOC(cpu) < 0)
- return -1;
-
- defs->cpus[i] = cpu;
+ qemuMonitorCPUDefInfoPtr cpu = defs->cpus + i;
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 7b8f63b11e..18ccf271f5 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -463,16 +463,16 @@ testQemuMonitorJSONGetCPUDefinitions(const void *opaque)
#define CHECK_FULL(i, wantname, Usable) \
do { \
- if (STRNEQ(defs->cpus[i]->name, (wantname))) { \
+ if (STRNEQ(defs->cpus[i].name, (wantname))) { \
virReportError(VIR_ERR_INTERNAL_ERROR, \
"name %s is not %s", \
- defs->cpus[i]->name, (wantname)); \
+ defs->cpus[i].name, (wantname)); \
return -1; \
} \
- if (defs->cpus[i]->usable != (Usable)) { \
+ if (defs->cpus[i].usable != (Usable)) { \
virReportError(VIR_ERR_INTERNAL_ERROR, \
"%s: expecting usable flag %d, got %d", \
- defs->cpus[i]->name, Usable,
defs->cpus[i]->usable); \
+ defs->cpus[i].name, Usable, defs->cpus[i].usable); \
return -1; \
} \
} while (0)
--
2.23.0