[libvirt] [PATCH]util: Helper function for checking existence of hook files for specific driver

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Wed Sep 25 09:50:47 UTC 2013


From: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>

We refresh the status of hook scripts
only when start/restart libvirt or reloads its configuration.
But hooks scripts may be changed.
This function will help to check its existence.
And we do not need to start/restart libvirt if
we add/remove hook files.

Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
 src/util/virhook.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/util/virhook.c b/src/util/virhook.c
index 159efdb..c4a1a15 100644
--- a/src/util/virhook.c
+++ b/src/util/virhook.c
@@ -129,6 +129,12 @@ virHookCheck(int no, const char *driver) {
     return ret;
 }
 
+static int
+virHookDriverCheck(int driver) {
+    return virHookCheck(driver,
+                        virHookDriverTypeToString(driver));
+}
+
 /*
  * virHookInitialize:
  *
@@ -170,11 +176,12 @@ virHookPresent(int driver) {
     if ((driver < VIR_HOOK_DRIVER_DAEMON) ||
         (driver >= VIR_HOOK_DRIVER_LAST))
         return 0;
-    if (virHooksFound == -1)
+    if (virHookDriverCheck(driver) != 1) {
+        VIR_DEBUG("Driver %s hooks files not found",
+                  virHookDriverTypeToString(driver));
         return 0;
+    }
 
-    if ((virHooksFound & (1 << driver)) == 0)
-        return 0;
     return 1;
 }
 
-- 
1.8.2.1




More information about the libvir-list mailing list