mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-13 11:15:08 +00:00
virtpm: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
db7eede6b4
commit
ae24a63ef8
@ -137,18 +137,12 @@ static int virTPMEmulatorInit(bool quiet);
|
|||||||
static char *
|
static char *
|
||||||
virTPMBinaryGetPath(virTPMBinary binary)
|
virTPMBinaryGetPath(virTPMBinary binary)
|
||||||
{
|
{
|
||||||
char *s = NULL;
|
VIR_LOCK_GUARD lock = virLockGuardLock(&swtpm_tools_lock);
|
||||||
|
|
||||||
virMutexLock(&swtpm_tools_lock);
|
|
||||||
|
|
||||||
if (virTPMEmulatorInit(false) < 0)
|
if (virTPMEmulatorInit(false) < 0)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
s = g_strdup(swtpmBinaries[binary].path);
|
return g_strdup(swtpmBinaries[binary].path);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virMutexUnlock(&swtpm_tools_lock);
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
@ -171,20 +165,14 @@ virTPMGetSwtpmIoctl(void)
|
|||||||
|
|
||||||
bool virTPMHasSwtpm(void)
|
bool virTPMHasSwtpm(void)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
VIR_LOCK_GUARD lock = virLockGuardLock(&swtpm_tools_lock);
|
||||||
|
|
||||||
virMutexLock(&swtpm_tools_lock);
|
|
||||||
|
|
||||||
if (virTPMEmulatorInit(true) < 0)
|
if (virTPMEmulatorInit(true) < 0)
|
||||||
goto cleanup;
|
return false;
|
||||||
|
|
||||||
ret = swtpmBinaries[VIR_TPM_BINARY_SWTPM].path != NULL &&
|
return swtpmBinaries[VIR_TPM_BINARY_SWTPM].path != NULL &&
|
||||||
swtpmBinaries[VIR_TPM_BINARY_SWTPM_SETUP].path != NULL &&
|
swtpmBinaries[VIR_TPM_BINARY_SWTPM_SETUP].path != NULL &&
|
||||||
swtpmBinaries[VIR_TPM_BINARY_SWTPM_IOCTL].path != NULL;
|
swtpmBinaries[VIR_TPM_BINARY_SWTPM_IOCTL].path != NULL;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virMutexUnlock(&swtpm_tools_lock);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virTPMExecGetCaps
|
/* virTPMExecGetCaps
|
||||||
@ -341,12 +329,10 @@ static bool
|
|||||||
virTPMBinaryGetCaps(virTPMBinary binary,
|
virTPMBinaryGetCaps(virTPMBinary binary,
|
||||||
unsigned int cap)
|
unsigned int cap)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
VIR_LOCK_GUARD lock = virLockGuardLock(&swtpm_tools_lock);
|
||||||
|
|
||||||
virMutexLock(&swtpm_tools_lock);
|
|
||||||
|
|
||||||
if (virTPMEmulatorInit(false) < 0)
|
if (virTPMEmulatorInit(false) < 0)
|
||||||
goto cleanup;
|
return false;
|
||||||
|
|
||||||
if (!swtpmBinaries[binary].caps &&
|
if (!swtpmBinaries[binary].caps &&
|
||||||
swtpmBinaries[binary].capsParse) {
|
swtpmBinaries[binary].capsParse) {
|
||||||
@ -355,12 +341,11 @@ virTPMBinaryGetCaps(virTPMBinary binary,
|
|||||||
swtpmBinaries[binary].path,
|
swtpmBinaries[binary].path,
|
||||||
swtpmBinaries[binary].parm);
|
swtpmBinaries[binary].parm);
|
||||||
}
|
}
|
||||||
if (swtpmBinaries[binary].caps)
|
|
||||||
ret = virBitmapIsBitSet(swtpmBinaries[binary].caps, cap);
|
|
||||||
|
|
||||||
cleanup:
|
if (!swtpmBinaries[binary].caps)
|
||||||
virMutexUnlock(&swtpm_tools_lock);
|
return false;
|
||||||
return ret;
|
|
||||||
|
return virBitmapIsBitSet(swtpmBinaries[binary].caps, cap);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
Loading…
Reference in New Issue
Block a user