memory: hotplug: sort by numerical ID rather than slot when unplugging

While, usually, the slot should match the ID, it's not explicitly
guaranteed and relies on QEMU internals. Using the numerical ID is
more future-proof and more consistent with plugging, where no slot
information (except the maximum limit) is relied upon.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fiona Ebner 2023-03-16 10:31:59 +01:00
parent d1b25a2267
commit 2cf203194b

View File

@ -201,7 +201,7 @@ sub qemu_memory_hotplug {
my $dimms = qemu_memdevices_list($vmid, 'dimm');
my $current_size = $memory;
for my $name (sort { $dimms->{$b}->{slot} <=> $dimms->{$a}->{slot} } keys %$dimms) {
for my $name (sort { ($b =~ /^dimm(\d+)$/)[0] <=> ($a =~ /^dimm(\d+)$/)[0] } keys %$dimms) {
my $dimm_size = $dimms->{$name}->{size} / 1024 / 1024;