secret: Factor out mutex

If the mutex is part of the `driver` object, it cannot guard that
object's creation and destruction perfectly.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Tim Wiederhake 2022-02-08 14:26:25 +01:00
parent ee0bc89470
commit 53850638d8

View File

@ -52,9 +52,10 @@ enum { SECRET_MAX_XML_FILE = 10*1024*1024 };
/* Internal driver state */
static virMutex mutex = VIR_MUTEX_INITIALIZER;
typedef struct _virSecretDriverState virSecretDriverState;
struct _virSecretDriverState {
virMutex lock;
bool privileged; /* readonly */
char *embeddedRoot; /* readonly */
int embeddedRefs;
@ -74,14 +75,14 @@ static virSecretDriverState *driver;
static void
secretDriverLock(void)
{
virMutexLock(&driver->lock);
virMutexLock(&mutex);
}
static void
secretDriverUnlock(void)
{
virMutexUnlock(&driver->lock);
virMutexUnlock(&mutex);
}
@ -463,7 +464,6 @@ secretStateCleanup(void)
VIR_FREE(driver->stateDir);
secretDriverUnlock();
virMutexDestroy(&driver->lock);
VIR_FREE(driver);
return 0;
@ -479,10 +479,6 @@ secretStateInitialize(bool privileged,
driver = g_new0(virSecretDriverState, 1);
driver->lockFD = -1;
if (virMutexInit(&driver->lock) < 0) {
VIR_FREE(driver);
return VIR_DRV_STATE_INIT_ERROR;
}
secretDriverLock();
driver->secretEventState = virObjectEventStateNew();