From cb7e13ffbf114d16db26be755838e1f455f3392f Mon Sep 17 00:00:00 2001 From: Luyao Huang Date: Mon, 15 Jun 2015 20:33:49 +0800 Subject: [PATCH] qemu: Add a check for slot and base dimm address conflicts When hotplugging a memory device, there wasn't a check to determine if there is a conflict with the address space being used by the to be added memory device and any existing device which is disallowed by qemu. This patch adds a check to ensure the new device address doesn't conflict with any existing device. Signed-off-by: Luyao Huang --- src/qemu/qemu_command.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 5a83774ab..5dabd5e84 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4957,6 +4957,40 @@ qemuBuildMemoryDimmBackendStr(virDomainMemoryDefPtr mem, } +static bool +qemuCheckMemoryDimmConflict(virDomainDefPtr def, + virDomainMemoryDefPtr mem) +{ + size_t i; + + for (i = 0; i < def->nmems; i++) { + virDomainMemoryDefPtr tmp = def->mems[i]; + + if (tmp == mem || + tmp->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM) + continue; + + if (mem->info.addr.dimm.slot == tmp->info.addr.dimm.slot) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("memory device slot '%u' is already being " + "used by another memory device"), + mem->info.addr.dimm.slot); + return true; + } + + if (mem->info.addr.dimm.base != 0 && + mem->info.addr.dimm.base == tmp->info.addr.dimm.base) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("memory device base '0x%llx' is already being " + "used by another memory device"), + mem->info.addr.dimm.base); + return true; + } + } + + return false; +} + char * qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem, virDomainDefPtr def, @@ -4998,6 +5032,9 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem, mem->targetNode, mem->info.alias, mem->info.alias); if (mem->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM) { + if (qemuCheckMemoryDimmConflict(def, mem)) + return NULL; + virBufferAsprintf(&buf, ",slot=%d", mem->info.addr.dimm.slot); virBufferAsprintf(&buf, ",addr=%llu", mem->info.addr.dimm.base); } -- 2.39.5