mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 01:34:11 +03:00
qemu: Refresh the current size of virtio-mem on monitor reconnect
If the QEMU driver restarts it loses the track of the current size of virtio-mem (because it's runtime type of information and thus not stored in XML) and therefore, we have to refresh it when reconnecting to the domain monitor. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
9985f62b51
commit
5c2d6908a6
@ -8212,9 +8212,23 @@ qemuDomainUpdateMemoryDeviceInfo(virQEMUDriver *driver,
|
||||
if (!(dimm = virHashLookup(meminfo, mem->info.alias)))
|
||||
continue;
|
||||
|
||||
mem->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM;
|
||||
mem->info.addr.dimm.slot = dimm->slot;
|
||||
mem->info.addr.dimm.base = dimm->address;
|
||||
switch (mem->model) {
|
||||
case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
|
||||
mem->currentsize = VIR_DIV_UP(dimm->size, 1024);
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_MEMORY_MODEL_DIMM:
|
||||
case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
|
||||
mem->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM;
|
||||
mem->info.addr.dimm.slot = dimm->slot;
|
||||
mem->info.addr.dimm.base = dimm->address;
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
|
||||
case VIR_DOMAIN_MEMORY_MODEL_NONE:
|
||||
case VIR_DOMAIN_MEMORY_MODEL_LAST:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
virHashFree(meminfo);
|
||||
|
@ -1385,10 +1385,13 @@ int qemuMonitorSetIOThread(qemuMonitor *mon,
|
||||
|
||||
typedef struct _qemuMonitorMemoryDeviceInfo qemuMonitorMemoryDeviceInfo;
|
||||
struct _qemuMonitorMemoryDeviceInfo {
|
||||
/* For pc-dimm */
|
||||
unsigned long long address;
|
||||
unsigned int slot;
|
||||
bool hotplugged;
|
||||
bool hotpluggable;
|
||||
/* For virtio-mem */
|
||||
unsigned long long size; /* in bytes */
|
||||
};
|
||||
|
||||
int qemuMonitorGetMemoryDeviceInfo(qemuMonitor *mon,
|
||||
|
@ -7978,7 +7978,6 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon,
|
||||
virJSONValue *cmd;
|
||||
virJSONValue *reply = NULL;
|
||||
virJSONValue *data = NULL;
|
||||
qemuMonitorMemoryDeviceInfo *meminfo = NULL;
|
||||
size_t i;
|
||||
|
||||
if (!(cmd = qemuMonitorJSONMakeCommand("query-memory-devices", NULL)))
|
||||
@ -7999,6 +7998,9 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon,
|
||||
|
||||
for (i = 0; i < virJSONValueArraySize(data); i++) {
|
||||
virJSONValue *elem = virJSONValueArrayGet(data, i);
|
||||
g_autofree qemuMonitorMemoryDeviceInfo *meminfo = NULL;
|
||||
virJSONValue *dimminfo;
|
||||
const char *devalias;
|
||||
const char *type;
|
||||
|
||||
if (!(type = virJSONValueObjectGetString(elem, "type"))) {
|
||||
@ -8008,26 +8010,26 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(dimminfo = virJSONValueObjectGetObject(elem, "data"))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("query-memory-devices reply data doesn't "
|
||||
"contain enum data"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* While 'id' attribute is marked as optional in QEMU's QAPI
|
||||
* specification, Libvirt always sets it. Thus we can fail if not
|
||||
* present. */
|
||||
if (!(devalias = virJSONValueObjectGetString(dimminfo, "id"))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("dimm memory info data is missing 'id'"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
meminfo = g_new0(qemuMonitorMemoryDeviceInfo, 1);
|
||||
|
||||
/* dimm memory devices */
|
||||
if (STREQ(type, "dimm")) {
|
||||
virJSONValue *dimminfo;
|
||||
const char *devalias;
|
||||
|
||||
if (!(dimminfo = virJSONValueObjectGetObject(elem, "data"))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("query-memory-devices reply data doesn't "
|
||||
"contain enum data"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(devalias = virJSONValueObjectGetString(dimminfo, "id"))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("dimm memory info data is missing 'id'"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
meminfo = g_new0(qemuMonitorMemoryDeviceInfo, 1);
|
||||
|
||||
if (virJSONValueObjectGetNumberUlong(dimminfo, "addr",
|
||||
&meminfo->address) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
@ -8058,17 +8060,27 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon,
|
||||
|
||||
}
|
||||
|
||||
if (virHashAddEntry(info, devalias, meminfo) < 0)
|
||||
} else if (STREQ(type, "virtio-mem")) {
|
||||
if (virJSONValueObjectGetNumberUlong(dimminfo, "size",
|
||||
&meminfo->size) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("malformed/missing size in virtio memory info"));
|
||||
goto cleanup;
|
||||
|
||||
meminfo = NULL;
|
||||
}
|
||||
} else {
|
||||
/* type not handled yet */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (virHashAddEntry(info, devalias, meminfo) < 0)
|
||||
goto cleanup;
|
||||
|
||||
meminfo = NULL;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(meminfo);
|
||||
virJSONValueFree(cmd);
|
||||
virJSONValueFree(reply);
|
||||
return ret;
|
||||
|
@ -8718,6 +8718,9 @@ qemuProcessReconnect(void *opaque)
|
||||
|
||||
qemuDomainVcpuPersistOrder(obj->def);
|
||||
|
||||
if (qemuDomainUpdateMemoryDeviceInfo(driver, obj, QEMU_ASYNC_JOB_NONE) < 0)
|
||||
goto error;
|
||||
|
||||
if (qemuProcessDetectIOThreadPIDs(driver, obj, QEMU_ASYNC_JOB_NONE) < 0)
|
||||
goto error;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user