vc:qemu: Fix id calculation of memory hotplug

QMP doesn't guarantee the order of the array that is returned by
`query-memory-devices` command. So we would better search the whole
array to find out the current max slot, rather than simply use the last
element's slot.

Fixes: #1362

Signed-off-by: Li Yuxuan <liyuxuan04@baidu.com>
This commit is contained in:
Li Yuxuan 2019-03-13 15:37:57 +08:00
parent 7ff18192a4
commit 4e81522571

View File

@ -1220,7 +1220,13 @@ func (q *qemu) hotplugAddMemory(memDev *memoryDevice) (int, error) {
}
if len(memoryDevices) != 0 {
memDev.slot = memoryDevices[len(memoryDevices)-1].Data.Slot + 1
maxSlot := -1
for _, device := range memoryDevices {
if maxSlot < device.Data.Slot {
maxSlot = device.Data.Slot
}
}
memDev.slot = maxSlot + 1
}
err = q.qmpMonitorCh.qmp.ExecHotplugMemory(q.qmpMonitorCh.ctx, "memory-backend-ram", "mem"+strconv.Itoa(memDev.slot), "", memDev.sizeMB)
if err != nil {