[libvirt] [PATCH 3/3] sanlock: Properly init io_timeout

Michal Privoznik mprivozn at redhat.com
Thu Sep 15 14:35:55 UTC 2016


https://bugzilla.redhat.com/show_bug.cgi?id=1292984

Hold on to your hats, because this is gonna be wild.

In bd3e16a3 I've tried to expose sanlock io_timeout. What I had
not realized (because there is like no documentation for sanlock
at all) was very unusual way their APIs work. Basically, what we
do currently is:

    sanlock_add_lockspace_timeout(&ls, io_timeout);

which adds a lockspace to sanlock daemon. One would expect that
io_timeout sets the io_timeout for it. Nah! That's where you are
completely off the tracks. It sets timeout for next lockspace you
will probably add later. Therefore:

   sanlock_add_lockspace_timeout(&ls, io_timeout = 10);
   /* adds new lockspace with default io_timeout */

   sanlock_add_lockspace_timeout(&ls, io_timeout = 20);
   /* adds new lockspace with io_timeout = 10 */

   sanlock_add_lockspace_timeout(&ls, io_timeout = 40);
   /* adds new lockspace with io_timeout = 20 */

And so on. You get the picture.
Fortunately, we don't allow setting io_timeout per domain or per
domain disk. So we just need to set the default used in the very
first step and hope for the best (as all the io_timeout-s used
later will have the same value).

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/locking/lock_driver_sanlock.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c
index f09027f..ee1ee67 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -157,6 +157,29 @@ static int virLockManagerSanlockLoadConfig(virLockManagerSanlockDriverPtr driver
     return ret;
 }
 
+static int
+virLockManagerSanlockInitLockspace(virLockManagerSanlockDriverPtr driver,
+                                   struct sanlk_lockspace *ls)
+{
+    int ret;
+
+#ifdef HAVE_SANLOCK_IO_TIMEOUT
+    const int max_hosts = 0; /* defaults used in sanlock_init() implementation */
+    const unsigned int lockspaceFlags = 0;
+
+    ret = sanlock_write_lockspace(ls, max_hosts, lockspaceFlags, driver->io_timeout);
+#else
+    if (driver->io_timeout) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("unable to use io_timeout with this version of sanlock"));
+        return -ENOTSUP;
+    }
+
+    ret = sanlock_init(ls, NULL, 0, 0);
+#endif
+    return ret;
+}
+
 /* How much ms sleep before retrying to add a lockspace? */
 #define LOCKSPACE_SLEEP 100
 /* How many times try adding a lockspace? */
@@ -267,7 +290,7 @@ virLockManagerSanlockSetupLockspace(virLockManagerSanlockDriverPtr driver)
                 goto error_unlink;
             }
 
-            if ((rv = sanlock_init(&ls, NULL, 0, 0)) < 0) {
+            if ((rv = virLockManagerSanlockInitLockspace(driver, &ls) < 0)) {
                 if (rv <= -200)
                     virReportError(VIR_ERR_INTERNAL_ERROR,
                                    _("Unable to initialize lockspace %s: error %d"),
-- 
2.8.4




More information about the libvir-list mailing list