mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
Use atomic ops to increment nextvmid
Use atomic ops to increment nextvmid and encapsulate it in a method to prevent accidental non-atomic access
This commit is contained in:
parent
582c445a96
commit
6ffcab65c9
@ -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
|
||||
@ -782,3 +783,8 @@ qemuRemoveSharedDisk(virHashTablePtr sharedDisks,
|
||||
VIR_FREE(key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qemuDriverAllocateID(virQEMUDriverPtr driver)
|
||||
{
|
||||
return virAtomicIntInc(&driver->nextvmid);
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -3586,7 +3586,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);
|
||||
|
||||
@ -4438,7 +4438,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);
|
||||
|
Loading…
Reference in New Issue
Block a user