mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
storage: acquire a pidfile in the driver root directory
When we allow multiple instances of the driver for the same user account, using a separate root directory, we need to ensure mutual exclusion. Use a pidfile to guarantee this. In privileged libvirtd this ends up locking /var/run/libvirt/storage/driver.pid In unprivileged libvirtd this ends up locking /run/user/$UID/libvirt/storage/run/driver.pid NB, the latter can vary depending on $XDG_RUNTIME_DIR Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
c03aef7c87
commit
44a5ba2af8
@ -37,6 +37,9 @@ typedef virStorageDriverState *virStorageDriverStatePtr;
|
||||
struct _virStorageDriverState {
|
||||
virMutex lock;
|
||||
|
||||
/* pid file FD, ensures two copies of the driver can't use the same root */
|
||||
int lockFD;
|
||||
|
||||
virStoragePoolObjListPtr pools;
|
||||
|
||||
char *configDir;
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "virlog.h"
|
||||
#include "virfile.h"
|
||||
#include "virfdstream.h"
|
||||
#include "virpidfile.h"
|
||||
#include "configmake.h"
|
||||
#include "virsecret.h"
|
||||
#include "virstring.h"
|
||||
@ -256,6 +257,7 @@ storageStateInitialize(bool privileged,
|
||||
if (VIR_ALLOC(driver) < 0)
|
||||
return -1;
|
||||
|
||||
driver->lockFD = -1;
|
||||
if (virMutexInit(&driver->lock) < 0) {
|
||||
VIR_FREE(driver);
|
||||
return -1;
|
||||
@ -296,6 +298,11 @@ storageStateInitialize(bool privileged,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((driver->lockFD =
|
||||
virPidFileAcquire(driver->stateDir, "driver",
|
||||
true, getpid())) < 0)
|
||||
goto error;
|
||||
|
||||
if (virStoragePoolObjLoadAllState(driver->pools,
|
||||
driver->stateDir) < 0)
|
||||
goto error;
|
||||
@ -371,6 +378,10 @@ storageStateCleanup(void)
|
||||
/* free inactive pools */
|
||||
virObjectUnref(driver->pools);
|
||||
|
||||
if (driver->lockFD != -1)
|
||||
virPidFileRelease(driver->stateDir, "driver",
|
||||
driver->lockFD);
|
||||
|
||||
VIR_FREE(driver->configDir);
|
||||
VIR_FREE(driver->autostartDir);
|
||||
VIR_FREE(driver->stateDir);
|
||||
|
Loading…
x
Reference in New Issue
Block a user