qemu_monitor: Decouple switch()-es in qemuMonitorJSONGetMemoryDeviceInfo()

There are two switch() statements over the same variable inside
of qemuMonitorJSONGetMemoryDeviceInfo(). Join them together into
one switch.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
This commit is contained in:
Michal Privoznik 2023-02-27 10:22:28 +01:00
parent f173f6a79c
commit 61233dfbee

View File

@ -7233,6 +7233,8 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon,
return -1;
}
meminfo = g_new0(qemuMonitorMemoryDeviceInfo, 1);
switch ((virDomainMemoryModel) model) {
case VIR_DOMAIN_MEMORY_MODEL_DIMM:
case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
@ -7245,28 +7247,9 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon,
_("dimm memory info data is missing 'id'"));
return -1;
}
break;
case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
if (!(devalias = virJSONValueObjectGetString(dimminfo, "memdev"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("sgx-epc memory info data is missing 'memdev'"));
return -1;
}
break;
case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
case VIR_DOMAIN_MEMORY_MODEL_NONE:
case VIR_DOMAIN_MEMORY_MODEL_LAST:
/* type not handled yet */
continue;
}
meminfo = g_new0(qemuMonitorMemoryDeviceInfo, 1);
switch ((virDomainMemoryModel) model) {
case VIR_DOMAIN_MEMORY_MODEL_DIMM:
case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
if (model == VIR_DOMAIN_MEMORY_MODEL_DIMM ||
model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM) {
if (virJSONValueObjectGetNumberUlong(dimminfo, "addr",
&meminfo->address) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -7296,18 +7279,22 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon,
return -1;
}
break;
case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
} else if (model == VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM) {
if (virJSONValueObjectGetNumberUlong(dimminfo, "size",
&meminfo->size) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("malformed/missing size in virtio memory info"));
return -1;
}
}
break;
case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
if (!(devalias = virJSONValueObjectGetString(dimminfo, "memdev"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("sgx-epc memory info data is missing 'memdev'"));
return -1;
}
if (virJSONValueObjectGetNumberUlong(dimminfo, "memaddr",
&meminfo->address) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",