[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v3 15/28] locking: Introduce virLockManagerClearResources



This is a counterpart to virLockManagerAddResource. It is going
to be handy when using one lock manager to lock multiple files
step by step.

Signed-off-by: Michal Privoznik <mprivozn redhat com>
---
 src/libvirt_private.syms        |  1 +
 src/locking/lock_driver.h       |  5 +++++
 src/locking/lock_driver_lockd.c | 27 ++++++++++++++++++++++++++-
 src/locking/lock_driver_nop.c   |  6 ++++++
 src/locking/lock_manager.c      | 12 ++++++++++++
 src/locking/lock_manager.h      |  3 +++
 6 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 47ea35f864..42f15f117e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1293,6 +1293,7 @@ virDomainLockProcessStart;
 # locking/lock_manager.h
 virLockManagerAcquire;
 virLockManagerAddResource;
+virLockManagerClearResources;
 virLockManagerFree;
 virLockManagerInquire;
 virLockManagerNew;
diff --git a/src/locking/lock_driver.h b/src/locking/lock_driver.h
index 9be0abcfba..59c4c3aac7 100644
--- a/src/locking/lock_driver.h
+++ b/src/locking/lock_driver.h
@@ -228,6 +228,10 @@ typedef int (*virLockDriverAddResource)(virLockManagerPtr man,
                                         virLockManagerParamPtr params,
                                         unsigned int flags);
 
+
+typedef int (*virLockDriverClearResource)(virLockManagerPtr mgr,
+                                          unsigned int flags);
+
 /**
  * virLockDriverAcquire:
  * @manager: the lock manager context
@@ -313,6 +317,7 @@ struct _virLockDriver {
     virLockDriverFree drvFree;
 
     virLockDriverAddResource drvAddResource;
+    virLockDriverClearResource drvClearResources;
 
     virLockDriverAcquire drvAcquire;
     virLockDriverRelease drvRelease;
diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c
index d7cb183d7a..4883e89ac6 100644
--- a/src/locking/lock_driver_lockd.c
+++ b/src/locking/lock_driver_lockd.c
@@ -402,8 +402,9 @@ static int virLockManagerLockDaemonDeinit(void)
     return 0;
 }
 
+
 static void
-virLockManagerLockDaemonPrivateFree(virLockManagerLockDaemonPrivatePtr priv)
+virLockManagerLockDaemonFreeResources(virLockManagerLockDaemonPrivatePtr priv)
 {
     size_t i;
 
@@ -415,6 +416,17 @@ virLockManagerLockDaemonPrivateFree(virLockManagerLockDaemonPrivatePtr priv)
         VIR_FREE(priv->resources[i].name);
     }
     VIR_FREE(priv->resources);
+    priv->nresources = 0;
+}
+
+
+static void
+virLockManagerLockDaemonPrivateFree(virLockManagerLockDaemonPrivatePtr priv)
+{
+    if (!priv)
+        return;
+
+    virLockManagerLockDaemonFreeResources(priv);
 
     switch (priv->type) {
     case VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN:
@@ -733,6 +745,18 @@ static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
 }
 
 
+static int virLockManagerLockDaemonClearResources(virLockManagerPtr lock,
+                                                  unsigned int flags)
+{
+    virLockManagerLockDaemonPrivatePtr priv = lock->privateData;
+
+    virCheckFlags(0, -1);
+
+    virLockManagerLockDaemonFreeResources(priv);
+    return 0;
+}
+
+
 static int virLockManagerLockDaemonAcquire(virLockManagerPtr lock,
                                            const char *state ATTRIBUTE_UNUSED,
                                            unsigned int flags,
@@ -881,6 +905,7 @@ virLockDriver virLockDriverImpl =
     .drvFree = virLockManagerLockDaemonFree,
 
     .drvAddResource = virLockManagerLockDaemonAddResource,
+    .drvClearResources = virLockManagerLockDaemonClearResources,
 
     .drvAcquire = virLockManagerLockDaemonAcquire,
     .drvRelease = virLockManagerLockDaemonRelease,
diff --git a/src/locking/lock_driver_nop.c b/src/locking/lock_driver_nop.c
index b5eb2952e9..26b36061fb 100644
--- a/src/locking/lock_driver_nop.c
+++ b/src/locking/lock_driver_nop.c
@@ -67,6 +67,11 @@ static int virLockManagerNopAddResource(virLockManagerPtr lock ATTRIBUTE_UNUSED,
     return 0;
 }
 
+static int virLockManagerNopClearResources(virLockManagerPtr lock ATTRIBUTE_UNUSED,
+                                           unsigned int flags_unused ATTRIBUTE_UNUSED)
+{
+    return 0;
+}
 
 static int virLockManagerNopAcquire(virLockManagerPtr lock ATTRIBUTE_UNUSED,
                                     const char *state ATTRIBUTE_UNUSED,
@@ -113,6 +118,7 @@ virLockDriver virLockDriverNop =
     .drvFree = virLockManagerNopFree,
 
     .drvAddResource = virLockManagerNopAddResource,
+    .drvClearResources = virLockManagerNopClearResources,
 
     .drvAcquire = virLockManagerNopAcquire,
     .drvRelease = virLockManagerNopRelease,
diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c
index 4ef9f9e692..292b142c14 100644
--- a/src/locking/lock_manager.c
+++ b/src/locking/lock_manager.c
@@ -340,6 +340,18 @@ int virLockManagerAddResource(virLockManagerPtr lock,
                                         flags);
 }
 
+
+int virLockManagerClearResources(virLockManagerPtr lock,
+                                 unsigned int flags)
+{
+    VIR_DEBUG("lock=%p flags=0X%x", lock, flags);
+
+    CHECK_MANAGER(drvClearResources, -1);
+
+    return lock->driver->drvClearResources(lock, flags);
+}
+
+
 int virLockManagerAcquire(virLockManagerPtr lock,
                           const char *state,
                           unsigned int flags,
diff --git a/src/locking/lock_manager.h b/src/locking/lock_manager.h
index 418975976c..8e0049ce0b 100644
--- a/src/locking/lock_manager.h
+++ b/src/locking/lock_manager.h
@@ -53,6 +53,9 @@ int virLockManagerAddResource(virLockManagerPtr manager,
                               virLockManagerParamPtr params,
                               unsigned int flags);
 
+int virLockManagerClearResources(virLockManagerPtr lock,
+                                 unsigned int flags);
+
 int virLockManagerAcquire(virLockManagerPtr manager,
                           const char *state,
                           unsigned int flags,
-- 
2.16.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]