Signed-off-by: Han Han <hhan(a)redhat.com>
---
src/locking/lock_daemon.c | 32 +++++++++---------------------
src/locking/lock_daemon.h | 4 ++--
src/locking/lock_daemon_dispatch.c | 32 +++++++++++++++---------------
3 files changed, 27 insertions(+), 41 deletions(-)
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index b0cd89375b..e1b495e8ba 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..457e909225 100644
--- a/src/locking/lock_daemon.h
+++ b/src/locking/lock_daemon.h
@@ -21,7 +21,7 @@
#pragma once
#include "virlockspace.h"
-#include "virthread.h"
+#include <glib.h>
typedef struct _virLockDaemon virLockDaemon;
typedef virLockDaemon *virLockDaemonPtr;
@@ -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..7a6b7af79b 100644
--- a/src/locking/lock_daemon_dispatch.c
+++ b/src/locking/lock_daemon_dispatch.c
@@ -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;
}
--
2.27.0