[PATCH v3 06/13] Use atomic ops to increment nextvmid

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

Use atomic ops to increment nextvmid and encapsulate it in a
methd to prevent accidental non-atomic access
---
 src/qemu/qemu_conf.c    | 6 ++++++
 src/qemu/qemu_conf.h    | 2 ++
 src/qemu/qemu_process.c | 4 ++--
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 48ad77f..68fc6ff 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -52,6 +52,7 @@
 #include "domain_nwfilter.h"
 #include "virfile.h"
 #include "virstring.h"
+#include "viratomic.h"
 #include "configmake.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
@@ -785,3 +786,8 @@ qemuRemoveSharedDisk(virHashTablePtr sharedDisks,
     VIR_FREE(key);
     return 0;
 }
+
+int qemuDriverAllocateID(virQEMUDriverPtr driver)
+{
+    return virAtomicIntInc(&driver->nextvmid);
+}
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index a96ff76..1cc277f 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -260,4 +260,6 @@ int qemuRemoveSharedDisk(virHashTablePtr sharedDisks,
 char * qemuGetSharedDiskKey(const char *disk_path)
     ATTRIBUTE_NONNULL(1);
 
+int qemuDriverAllocateID(virQEMUDriverPtr driver);
+
 #endif /* __QEMUD_CONF_H */
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 91da3f0..1585744 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3584,7 +3584,7 @@ int qemuProcessStart(virConnectPtr conn,
     if (virDomainObjSetDefTransient(driver->caps, vm, true) < 0)
         goto cleanup;
 
-    vm->def->id = driver->nextvmid++;
+    vm->def->id = qemuDriverAllocateID(driver);
     qemuDomainSetFakeReboot(driver, vm, false);
     virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_UNKNOWN);
 
@@ -4436,7 +4436,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
     if (virDomainObjSetDefTransient(driver->caps, vm, true) < 0)
         goto cleanup;
 
-    vm->def->id = driver->nextvmid++;
+    vm->def->id = qemuDriverAllocateID(driver);
 
     if (!driver->nactive && driver->inhibitCallback)
         driver->inhibitCallback(true, driver->inhibitOpaque);
-- 
1.8.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]