mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-09 20:07:49 +00:00
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:
parent
7ff18192a4
commit
4e81522571
@ -1220,7 +1220,13 @@ func (q *qemu) hotplugAddMemory(memDev *memoryDevice) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(memoryDevices) != 0 {
|
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)
|
err = q.qmpMonitorCh.qmp.ExecHotplugMemory(q.qmpMonitorCh.ctx, "memory-backend-ram", "mem"+strconv.Itoa(memDev.slot), "", memDev.sizeMB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user