From e8d5eb0cdec4c4c2e7aea2ebf66dfe6f5b4cb526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Fri, 31 Jan 2020 15:27:37 +0100 Subject: [PATCH] qemu: Fix domain ID allocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The rewrite to use GLib's atomic ops functions changed the behavior of virAtomicIntInc - before it returned the pre-increment value. Most of the callers using its value were adjusted, but the one in qemuDriverAllocateID was not. If libvirtd would reconnect to a running domain during startup, the next started domain would get the same ID: $ virsh list Id Name State -------------------------- 1 f28live running 1 f28live1 running Use the g_atomic_add function directly (as recommended in viratomic.h) and add 1 to the result. This also restores the usual numbering from 1 instead of 0. Signed-off-by: Ján Tomko Fixes: 7b9645a7d127a374b8d1c83fdf9789706dbab2c9 Reviewed-by: Peter Krempa --- src/qemu/qemu_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index e5051027fc..0b119cbe78 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1858,7 +1858,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev) int qemuDriverAllocateID(virQEMUDriverPtr driver) { - return virAtomicIntInc(&driver->lastvmid); + return g_atomic_int_add(&driver->lastvmid, 1) + 1; }