Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/locking/lock_daemon.c | 32 +++++++++---------------------
src/locking/lock_daemon.h | 2 +-
src/locking/lock_daemon_dispatch.c | 32 ++++++++----------------------
3 files changed, 18 insertions(+), 48 deletions(-)
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index 4eff63014a..69aa1f688a 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -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;
}
diff --git a/src/locking/lock_daemon.h b/src/locking/lock_daemon.h
index 7d30551c32..2405ef2036 100644
--- a/src/locking/lock_daemon.h
+++ b/src/locking/lock_daemon.h
@@ -30,7 +30,7 @@ typedef struct _virLockDaemonClient virLockDaemonClient;
typedef virLockDaemonClient *virLockDaemonClientPtr;
struct _virLockDaemonClient {
- virMutex lock;
+ GMutex lock;
bool restricted;
pid_t ownerPid;
diff --git a/src/locking/lock_daemon_dispatch.c b/src/locking/lock_daemon_dispatch.c
index 1a53772366..1587785606 100644
--- a/src/locking/lock_daemon_dispatch.c
+++ b/src/locking/lock_daemon_dispatch.c
@@ -48,8 +48,7 @@ virLockSpaceProtocolDispatchAcquireResource(virNetServerPtr server
G_GNUC_UNUSED
virNetServerClientGetPrivateData(client);
virLockSpacePtr lockspace;
unsigned int newFlags;
-
- virMutexLock(&priv->lock);
+ g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&priv->lock);
virCheckFlagsGoto(VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_SHARED |
VIR_LOCK_SPACE_PROTOCOL_ACQUIRE_RESOURCE_AUTOCREATE, cleanup);
@@ -90,7 +89,6 @@ virLockSpaceProtocolDispatchAcquireResource(virNetServerPtr server
G_GNUC_UNUSED
cleanup:
if (rv < 0)
virNetMessageSaveError(rerr);
- virMutexUnlock(&priv->lock);
return rv;
}
@@ -107,8 +105,7 @@ virLockSpaceProtocolDispatchCreateResource(virNetServerPtr server
G_GNUC_UNUSED,
virLockDaemonClientPtr priv =
virNetServerClientGetPrivateData(client);
virLockSpacePtr lockspace;
-
- virMutexLock(&priv->lock);
+ g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&priv->lock);
virCheckFlagsGoto(0, cleanup);
@@ -139,7 +136,6 @@ virLockSpaceProtocolDispatchCreateResource(virNetServerPtr server
G_GNUC_UNUSED,
cleanup:
if (rv < 0)
virNetMessageSaveError(rerr);
- virMutexUnlock(&priv->lock);
return rv;
}
@@ -156,8 +152,7 @@ virLockSpaceProtocolDispatchDeleteResource(virNetServerPtr server
G_GNUC_UNUSED,
virLockDaemonClientPtr priv =
virNetServerClientGetPrivateData(client);
virLockSpacePtr lockspace;
-
- virMutexLock(&priv->lock);
+ g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&priv->lock);
virCheckFlagsGoto(0, cleanup);
@@ -188,7 +183,6 @@ virLockSpaceProtocolDispatchDeleteResource(virNetServerPtr server
G_GNUC_UNUSED,
cleanup:
if (rv < 0)
virNetMessageSaveError(rerr);
- virMutexUnlock(&priv->lock);
return rv;
}
@@ -205,8 +199,7 @@ virLockSpaceProtocolDispatchNew(virNetServerPtr server G_GNUC_UNUSED,
virLockDaemonClientPtr priv =
virNetServerClientGetPrivateData(client);
virLockSpacePtr lockspace;
-
- virMutexLock(&priv->lock);
+ g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&priv->lock);
virCheckFlagsGoto(0, cleanup);
@@ -244,7 +237,6 @@ virLockSpaceProtocolDispatchNew(virNetServerPtr server G_GNUC_UNUSED,
cleanup:
if (rv < 0)
virNetMessageSaveError(rerr);
- virMutexUnlock(&priv->lock);
return rv;
}
@@ -260,8 +252,7 @@ virLockSpaceProtocolDispatchRegister(virNetServerPtr server
G_GNUC_UNUSED,
unsigned int flags = args->flags;
virLockDaemonClientPtr priv =
virNetServerClientGetPrivateData(client);
-
- virMutexLock(&priv->lock);
+ g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&priv->lock);
virCheckFlagsGoto(0, cleanup);
@@ -289,7 +280,6 @@ virLockSpaceProtocolDispatchRegister(virNetServerPtr server
G_GNUC_UNUSED,
cleanup:
if (rv < 0)
virNetMessageSaveError(rerr);
- virMutexUnlock(&priv->lock);
return rv;
}
@@ -306,8 +296,7 @@ virLockSpaceProtocolDispatchReleaseResource(virNetServerPtr server
G_GNUC_UNUSED
virLockDaemonClientPtr priv =
virNetServerClientGetPrivateData(client);
virLockSpacePtr lockspace;
-
- virMutexLock(&priv->lock);
+ g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&priv->lock);
virCheckFlagsGoto(0, cleanup);
@@ -340,7 +329,6 @@ virLockSpaceProtocolDispatchReleaseResource(virNetServerPtr server
G_GNUC_UNUSED
cleanup:
if (rv < 0)
virNetMessageSaveError(rerr);
- virMutexUnlock(&priv->lock);
return rv;
}
@@ -356,8 +344,7 @@ virLockSpaceProtocolDispatchRestrict(virNetServerPtr server
G_GNUC_UNUSED,
unsigned int flags = args->flags;
virLockDaemonClientPtr priv =
virNetServerClientGetPrivateData(client);
-
- virMutexLock(&priv->lock);
+ g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&priv->lock);
virCheckFlagsGoto(0, cleanup);
@@ -379,7 +366,6 @@ virLockSpaceProtocolDispatchRestrict(virNetServerPtr server
G_GNUC_UNUSED,
cleanup:
if (rv < 0)
virNetMessageSaveError(rerr);
- virMutexUnlock(&priv->lock);
return rv;
}
@@ -395,8 +381,7 @@ virLockSpaceProtocolDispatchCreateLockSpace(virNetServerPtr server
G_GNUC_UNUSED
virLockDaemonClientPtr priv =
virNetServerClientGetPrivateData(client);
virLockSpacePtr lockspace;
-
- virMutexLock(&priv->lock);
+ g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&priv->lock);
if (priv->restricted) {
virReportError(VIR_ERR_OPERATION_DENIED, "%s",
@@ -424,6 +409,5 @@ virLockSpaceProtocolDispatchCreateLockSpace(virNetServerPtr server
G_GNUC_UNUSED
cleanup:
if (rv < 0)
virNetMessageSaveError(rerr);
- virMutexUnlock(&priv->lock);
return rv;
}
--
2.25.2