From: Peter Krempa <[email protected]>

Add configuration option so additional lockspaces can be registered.
These are useful to use manual <lease>, which can't be used on the
default approach of registering the lease against a file.

With this it's also now possible to use virtlockd in manual mode
(disabling auto_disk_leases).

Signed-off-by: Peter Krempa <[email protected]>
---
 src/locking/libvirt_lockd.aug         |  8 ++++++++
 src/locking/lock_driver_lockd.c       | 13 +++++++++++++
 src/locking/lockd.conf                | 10 ++++++++++
 src/locking/test_libvirt_lockd.aug.in |  4 ++++
 4 files changed, 35 insertions(+)

diff --git a/src/locking/libvirt_lockd.aug b/src/locking/libvirt_lockd.aug
index 8cdb71a8a4..8f4fbb5713 100644
--- a/src/locking/libvirt_lockd.aug
+++ b/src/locking/libvirt_lockd.aug
@@ -7,13 +7,20 @@ module Libvirt_lockd =
    let value_sep   = del /[ \t]*=[ \t]*/  " = "
    let indent = del /[ \t]*/ ""

+   let array_sep  = del /,[ \t\n]*/ ", "
+   let array_start = del /\[[ \t\n]*/ "[ "
+   let array_end = del /\]/ "]"
+
    let str_val = del /\"/ "\"" . store /[^\"]*/ . del /\"/ "\""
    let bool_val = store /0|1/
    let int_val = store /[0-9]+/
+   let str_array_element = [ seq "el" . str_val ] . del /[ \t\n]*/ ""
+   let str_array_val = counter "el" . array_start . ( str_array_element . ( 
array_sep . str_array_element ) * ) ? . array_end

    let str_entry       (kw:string) = [ key kw . value_sep . str_val ]
    let bool_entry      (kw:string) = [ key kw . value_sep . bool_val ]
    let int_entry       (kw:string) = [ key kw . value_sep . int_val ]
+   let str_array_entry (kw:string) = [ key kw . value_sep . str_array_val ]


    (* Each entry in the config is one of the following three ... *)
@@ -22,6 +29,7 @@ module Libvirt_lockd =
              | str_entry "file_lockspace_dir"
              | str_entry "lvm_lockspace_dir"
              | str_entry "scsi_lockspace_dir"
+             | str_array_entry "extra_lockspace_dirs"
    let comment = [ label "#comment" . del /#[ \t]*/ "# " .  store /([^ 
\t\n][^\n]*)?/ . del /\n/ "\n" ]
    let empty = [ label "#empty" . eol ]

diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c
index a3bb285eec..09149bded5 100644
--- a/src/locking/lock_driver_lockd.c
+++ b/src/locking/lock_driver_lockd.c
@@ -74,6 +74,8 @@ struct _virLockManagerLockDaemonDriver {
     char *fileLockSpaceDir;
     char *lvmLockSpaceDir;
     char *scsiLockSpaceDir;
+
+    char **extraLockSpaceDirs;
 };

 static virLockManagerLockDaemonDriver *driver;
@@ -111,6 +113,10 @@ static int virLockManagerLockDaemonLoadConfig(const char 
*configFile)
     if (virConfGetValueBool(conf, "require_lease_for_disks", 
&driver->requireLeaseForDisks) < 0)
         return -1;

+    if (virConfGetValueStringList(conf, "extra_lockspace_dirs", false,
+                                  &driver->extraLockSpaceDirs) < 0)
+        return -1;
+
     return 0;
 }

@@ -288,6 +294,7 @@ static int virLockManagerLockDaemonInit(unsigned int 
version,
                                         const char *configFile,
                                         unsigned int flags)
 {
+    char **n;
     VIR_DEBUG("version=%u configFile=%s flags=0x%x", version, 
NULLSTR(configFile), flags);

     virCheckFlags(0, -1);
@@ -317,6 +324,11 @@ static int virLockManagerLockDaemonInit(unsigned int 
version,
             goto error;
     }

+    for (n = driver->extraLockSpaceDirs; n && *n; n++) {
+        if (virLockManagerLockDaemonSetupLockspace(*n) < 0)
+            goto error;
+    }
+
     return 0;

  error:
@@ -332,6 +344,7 @@ static int virLockManagerLockDaemonDeinit(void)
     VIR_FREE(driver->scsiLockSpaceDir);
     VIR_FREE(driver->lvmLockSpaceDir);
     VIR_FREE(driver->fileLockSpaceDir);
+    g_strfreev(driver->extraLockSpaceDirs);
     VIR_FREE(driver);

     return 0;
diff --git a/src/locking/lockd.conf b/src/locking/lockd.conf
index fa437604e6..ed7703ee06 100644
--- a/src/locking/lockd.conf
+++ b/src/locking/lockd.conf
@@ -65,3 +65,13 @@
 # storage.
 #
 #scsi_lockspace_dir = "/var/lib/libvirt/lockd/scsivolumes"
+
+
+#
+# Additional lockspaces used for manual locks via the <lease> element.
+#
+# Typically these directories would be located on a shared
+# filesystem visible to all hosts accessing the same
+# storage.
+#
+#extra_lockspace_dirs = [ "/custom/lockspace1", "/custom/lockspace2" ]
diff --git a/src/locking/test_libvirt_lockd.aug.in 
b/src/locking/test_libvirt_lockd.aug.in
index 0f3b57eb34..249f765916 100644
--- a/src/locking/test_libvirt_lockd.aug.in
+++ b/src/locking/test_libvirt_lockd.aug.in
@@ -7,3 +7,7 @@ module Test_libvirt_lockd =
 { "file_lockspace_dir" = "/var/lib/libvirt/lockd/files" }
 { "lvm_lockspace_dir" = "/var/lib/libvirt/lockd/lvmvolumes" }
 { "scsi_lockspace_dir" = "/var/lib/libvirt/lockd/scsivolumes" }
+{ "extra_lockspace_dirs"
+    { "1" = "/custom/lockspace1" }
+    { "2" = "/custom/lockspace2" }
+}
-- 
2.54.0

Reply via email to