mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
locking: Replace virMutex with GMutex
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Han Han <hhan@redhat.com>
This commit is contained in:
parent
925e34c71a
commit
809a2877ec
@ -59,7 +59,7 @@ VIR_LOG_INIT("locking.lock_daemon");
|
||||
#define VIR_LOCK_DAEMON_NUM_LOCKSPACES 3
|
||||
|
||||
struct _virLockDaemon {
|
||||
virMutex lock;
|
||||
GMutex lock;
|
||||
virNetDaemonPtr dmn;
|
||||
virHashTablePtr lockspaces;
|
||||
virLockSpacePtr defaultLockspace;
|
||||
@ -89,7 +89,7 @@ virLockDaemonFree(virLockDaemonPtr lockd)
|
||||
if (!lockd)
|
||||
return;
|
||||
|
||||
virMutexDestroy(&lockd->lock);
|
||||
g_mutex_clear(&lockd->lock);
|
||||
virObjectUnref(lockd->dmn);
|
||||
virHashFree(lockd->lockspaces);
|
||||
virLockSpaceFree(lockd->defaultLockspace);
|
||||
@ -100,13 +100,13 @@ virLockDaemonFree(virLockDaemonPtr lockd)
|
||||
static inline void
|
||||
virLockDaemonLock(virLockDaemonPtr lockd)
|
||||
{
|
||||
virMutexLock(&lockd->lock);
|
||||
g_mutex_lock(&lockd->lock);
|
||||
}
|
||||
|
||||
static inline void
|
||||
virLockDaemonUnlock(virLockDaemonPtr lockd)
|
||||
{
|
||||
virMutexUnlock(&lockd->lock);
|
||||
g_mutex_unlock(&lockd->lock);
|
||||
}
|
||||
|
||||
static void virLockDaemonLockSpaceDataFree(void *data)
|
||||
@ -123,12 +123,7 @@ virLockDaemonNew(virLockDaemonConfigPtr config, bool privileged)
|
||||
if (VIR_ALLOC(lockd) < 0)
|
||||
return NULL;
|
||||
|
||||
if (virMutexInit(&lockd->lock) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Unable to initialize mutex"));
|
||||
VIR_FREE(lockd);
|
||||
return NULL;
|
||||
}
|
||||
g_mutex_init(&lockd->lock);
|
||||
|
||||
if (!(lockd->dmn = virNetDaemonNew()))
|
||||
goto error;
|
||||
@ -220,12 +215,7 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged)
|
||||
if (VIR_ALLOC(lockd) < 0)
|
||||
return NULL;
|
||||
|
||||
if (virMutexInit(&lockd->lock) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Unable to initialize mutex"));
|
||||
VIR_FREE(lockd);
|
||||
return NULL;
|
||||
}
|
||||
g_mutex_init(&lockd->lock);
|
||||
|
||||
if (!(lockd->lockspaces = virHashCreate(VIR_LOCK_DAEMON_NUM_LOCKSPACES,
|
||||
virLockDaemonLockSpaceDataFree)))
|
||||
@ -450,7 +440,7 @@ virLockDaemonClientFree(void *opaque)
|
||||
}
|
||||
}
|
||||
|
||||
virMutexDestroy(&priv->lock);
|
||||
g_mutex_clear(&priv->lock);
|
||||
VIR_FREE(priv->ownerName);
|
||||
VIR_FREE(priv);
|
||||
}
|
||||
@ -469,11 +459,7 @@ virLockDaemonClientNew(virNetServerClientPtr client,
|
||||
if (VIR_ALLOC(priv) < 0)
|
||||
return NULL;
|
||||
|
||||
if (virMutexInit(&priv->lock) < 0) {
|
||||
VIR_FREE(priv);
|
||||
virReportSystemError(errno, "%s", _("unable to init mutex"));
|
||||
return NULL;
|
||||
}
|
||||
g_mutex_init(&priv->lock);
|
||||
|
||||
if (virNetServerClientGetUNIXIdentity(client,
|
||||
&clientuid,
|
||||
@ -508,7 +494,7 @@ virLockDaemonClientNew(virNetServerClientPtr client,
|
||||
return priv;
|
||||
|
||||
error:
|
||||
virMutexDestroy(&priv->lock);
|
||||
g_mutex_clear(&priv->lock);
|
||||
VIR_FREE(priv);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -21,7 +21,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "virlockspace.h"
|
||||
#include "virthread.h"
|
||||
|
||||
typedef struct _virLockDaemon virLockDaemon;
|
||||
typedef virLockDaemon *virLockDaemonPtr;
|
||||
@ -30,7 +29,7 @@ typedef struct _virLockDaemonClient virLockDaemonClient;
|
||||
typedef virLockDaemonClient *virLockDaemonClientPtr;
|
||||
|
||||
struct _virLockDaemonClient {
|
||||
virMutex lock;
|
||||
GMutex lock;
|
||||
bool restricted;
|
||||
|
||||
pid_t ownerPid;
|
||||
|
@ -49,7 +49,7 @@ virLockSpaceProtocolDispatchAcquireResource(virNetServerPtr server G_GNUC_UNUSED
|
||||
virLockSpacePtr lockspace;
|
||||
unsigned int newFlags;
|
||||
|
||||
virMutexLock(&priv->lock);
|
||||
g_mutex_lock(&priv->lock);
|
||||
|
||||
virCheckFlagsGoto(VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_SHARED |
|
||||
VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE, cleanup);
|
||||
@ -90,7 +90,7 @@ virLockSpaceProtocolDispatchAcquireResource(virNetServerPtr server G_GNUC_UNUSED
|
||||
cleanup:
|
||||
if (rv < 0)
|
||||
virNetMessageSaveError(rerr);
|
||||
virMutexUnlock(&priv->lock);
|
||||
g_mutex_unlock(&priv->lock);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ virLockSpaceProtocolDispatchCreateResource(virNetServerPtr server G_GNUC_UNUSED,
|
||||
virNetServerClientGetPrivateData(client);
|
||||
virLockSpacePtr lockspace;
|
||||
|
||||
virMutexLock(&priv->lock);
|
||||
g_mutex_lock(&priv->lock);
|
||||
|
||||
virCheckFlagsGoto(0, cleanup);
|
||||
|
||||
@ -139,7 +139,7 @@ virLockSpaceProtocolDispatchCreateResource(virNetServerPtr server G_GNUC_UNUSED,
|
||||
cleanup:
|
||||
if (rv < 0)
|
||||
virNetMessageSaveError(rerr);
|
||||
virMutexUnlock(&priv->lock);
|
||||
g_mutex_unlock(&priv->lock);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ virLockSpaceProtocolDispatchDeleteResource(virNetServerPtr server G_GNUC_UNUSED,
|
||||
virNetServerClientGetPrivateData(client);
|
||||
virLockSpacePtr lockspace;
|
||||
|
||||
virMutexLock(&priv->lock);
|
||||
g_mutex_lock(&priv->lock);
|
||||
|
||||
virCheckFlagsGoto(0, cleanup);
|
||||
|
||||
@ -188,7 +188,7 @@ virLockSpaceProtocolDispatchDeleteResource(virNetServerPtr server G_GNUC_UNUSED,
|
||||
cleanup:
|
||||
if (rv < 0)
|
||||
virNetMessageSaveError(rerr);
|
||||
virMutexUnlock(&priv->lock);
|
||||
g_mutex_unlock(&priv->lock);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ virLockSpaceProtocolDispatchNew(virNetServerPtr server G_GNUC_UNUSED,
|
||||
virNetServerClientGetPrivateData(client);
|
||||
virLockSpacePtr lockspace;
|
||||
|
||||
virMutexLock(&priv->lock);
|
||||
g_mutex_lock(&priv->lock);
|
||||
|
||||
virCheckFlagsGoto(0, cleanup);
|
||||
|
||||
@ -244,7 +244,7 @@ virLockSpaceProtocolDispatchNew(virNetServerPtr server G_GNUC_UNUSED,
|
||||
cleanup:
|
||||
if (rv < 0)
|
||||
virNetMessageSaveError(rerr);
|
||||
virMutexUnlock(&priv->lock);
|
||||
g_mutex_unlock(&priv->lock);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -261,7 +261,7 @@ virLockSpaceProtocolDispatchRegister(virNetServerPtr server G_GNUC_UNUSED,
|
||||
virLockDaemonClientPtr priv =
|
||||
virNetServerClientGetPrivateData(client);
|
||||
|
||||
virMutexLock(&priv->lock);
|
||||
g_mutex_lock(&priv->lock);
|
||||
|
||||
virCheckFlagsGoto(0, cleanup);
|
||||
|
||||
@ -289,7 +289,7 @@ virLockSpaceProtocolDispatchRegister(virNetServerPtr server G_GNUC_UNUSED,
|
||||
cleanup:
|
||||
if (rv < 0)
|
||||
virNetMessageSaveError(rerr);
|
||||
virMutexUnlock(&priv->lock);
|
||||
g_mutex_unlock(&priv->lock);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -307,7 +307,7 @@ virLockSpaceProtocolDispatchReleaseResource(virNetServerPtr server G_GNUC_UNUSED
|
||||
virNetServerClientGetPrivateData(client);
|
||||
virLockSpacePtr lockspace;
|
||||
|
||||
virMutexLock(&priv->lock);
|
||||
g_mutex_lock(&priv->lock);
|
||||
|
||||
virCheckFlagsGoto(0, cleanup);
|
||||
|
||||
@ -340,7 +340,7 @@ virLockSpaceProtocolDispatchReleaseResource(virNetServerPtr server G_GNUC_UNUSED
|
||||
cleanup:
|
||||
if (rv < 0)
|
||||
virNetMessageSaveError(rerr);
|
||||
virMutexUnlock(&priv->lock);
|
||||
g_mutex_unlock(&priv->lock);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -357,7 +357,7 @@ virLockSpaceProtocolDispatchRestrict(virNetServerPtr server G_GNUC_UNUSED,
|
||||
virLockDaemonClientPtr priv =
|
||||
virNetServerClientGetPrivateData(client);
|
||||
|
||||
virMutexLock(&priv->lock);
|
||||
g_mutex_lock(&priv->lock);
|
||||
|
||||
virCheckFlagsGoto(0, cleanup);
|
||||
|
||||
@ -379,7 +379,7 @@ virLockSpaceProtocolDispatchRestrict(virNetServerPtr server G_GNUC_UNUSED,
|
||||
cleanup:
|
||||
if (rv < 0)
|
||||
virNetMessageSaveError(rerr);
|
||||
virMutexUnlock(&priv->lock);
|
||||
g_mutex_unlock(&priv->lock);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -396,7 +396,7 @@ virLockSpaceProtocolDispatchCreateLockSpace(virNetServerPtr server G_GNUC_UNUSED
|
||||
virNetServerClientGetPrivateData(client);
|
||||
virLockSpacePtr lockspace;
|
||||
|
||||
virMutexLock(&priv->lock);
|
||||
g_mutex_lock(&priv->lock);
|
||||
|
||||
if (priv->restricted) {
|
||||
virReportError(VIR_ERR_OPERATION_DENIED, "%s",
|
||||
@ -424,6 +424,6 @@ virLockSpaceProtocolDispatchCreateLockSpace(virNetServerPtr server G_GNUC_UNUSED
|
||||
cleanup:
|
||||
if (rv < 0)
|
||||
virNetMessageSaveError(rerr);
|
||||
virMutexUnlock(&priv->lock);
|
||||
g_mutex_unlock(&priv->lock);
|
||||
return rv;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user