[PATCH qemu-server v2] api: record VM ID as used after a virtual machine is destroyed

Severen Redwood severen.redwood at sitehost.co.nz
Fri Oct 4 07:07:43 CEST 2024


After a virtual machine is destroyed, record that its ID has been used
via the `PVE::UsedVmidList` module so that the `/cluster/nextids`
endpoint can later optionally avoid suggesting previously used IDs.

Co-authored-by: Daniel Krambrock <krambrock at hrz.uni-marburg.de>
Signed-off-by: Severen Redwood <severen.redwood at sitehost.co.nz>
---
 PVE/API2/Qemu.pm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index d25a79fe..a01dec2c 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -2335,7 +2335,9 @@ __PACKAGE__->register_method({
 		    }
 		}
 
-		# only now remove the zombie config, else we can have reuse race
+		# only now mark the VM ID as previously used and remove the
+		# zombie config, else we can have reuse race
+		PVE::UsedVmidList::add_vmid($vmid);
 		PVE::QemuConfig->destroy_config($vmid);
 	    });
 	};
-- 
2.46.2




More information about the pve-devel mailing list