]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
locking: Add io_timeout to sanlock
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 23 Oct 2015 11:21:22 +0000 (13:21 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 18 Nov 2015 09:56:56 +0000 (10:56 +0100)
https://bugzilla.redhat.com/show_bug.cgi?id=1251190

So, if domain loses access to storage, sanlock tries to kill it
after some timeout. So far, the default is 80 seconds. But for
some scenarios this might not be enough. We should allow users to
adjust the timeout according to their needs.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
m4/virt-sanlock.m4
src/locking/libvirt_sanlock.aug
src/locking/lock_driver_sanlock.c
src/locking/sanlock.conf
src/locking/test_libvirt_sanlock.aug.in

index c7c0186f867b522733b6b4e46737348fce881735..d2a607d0457aeacf49e87ea8e7ae36066019802d 100644 (file)
@@ -46,6 +46,13 @@ AC_DEFUN([LIBVIRT_CHECK_SANLOCK],[
         [whether sanlock supports sanlock_inq_lockspace])
     fi
 
+    AC_CHECK_LIB([sanlock_client], [sanlock_add_lockspace_timeout],
+                 [sanlock_add_lockspace_timeout=yes], [sanlock_add_lockspace_timeout=no])
+    if test "x$sanlock_add_lockspace_timeout" = "xyes" ; then
+      AC_DEFINE_UNQUOTED([HAVE_SANLOCK_ADD_LOCKSPACE_TIMEOUT], 1,
+        [whether Sanlock supports sanlock_add_lockspace_timeout])
+    fi
+
     CPPFLAGS="$old_cppflags"
     LIBS="$old_libs"
   fi
index a78a4445c0ff14b2b5df175dd90ccd0dd2410341..88435902d2685b3e601c1277de7c038e8cdc8c65 100644 (file)
@@ -22,6 +22,7 @@ module Libvirt_sanlock =
              | int_entry "host_id"
              | bool_entry "require_lease_for_disks"
              | bool_entry "ignore_readonly_and_shared_disks"
+             | int_entry "io_timeout"
              | str_entry "user"
              | str_entry "group"
    let comment = [ label "#comment" . del /#[ \t]*/ "# " .  store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ]
index e052875e2569d4ddac68e5c094c45341147af14d..3069b82f5fca82f7ad89bcd38ce93f9d2905d789 100644 (file)
@@ -73,6 +73,7 @@ struct _virLockManagerSanlockDriver {
     int hostID;
     bool autoDiskLease;
     char *autoDiskLeasePath;
+    unsigned int io_timeout;
 
     /* under which permissions does sanlock run */
     uid_t user;
@@ -151,6 +152,10 @@ static int virLockManagerSanlockLoadConfig(const char *configFile)
     else
         driver->requireLeaseForDisks = !driver->autoDiskLease;
 
+    p = virConfGetValue(conf, "io_timeout");
+    CHECK_TYPE("io_timeout", VIR_CONF_ULONG);
+    if (p) driver->io_timeout = p->l;
+
     p = virConfGetValue(conf, "user");
     CHECK_TYPE("user", VIR_CONF_STRING);
     if (p) {
@@ -338,7 +343,17 @@ static int virLockManagerSanlockSetupLockspace(void)
      * or we can fallback to polling.
      */
  retry:
-    if ((rv = sanlock_add_lockspace(&ls, 0)) < 0) {
+#ifdef HAVE_SANLOCK_ADD_LOCKSPACE_TIMEOUT
+    rv = sanlock_add_lockspace_timeout(&ls, 0, driver->io_timeout);
+#else
+    if (driver->io_timeout) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("unable to use io_timeout with this version of sanlock"));
+        goto error;
+    }
+    rv = sanlock_add_lockspace(&ls, 0);
+#endif
+    if (rv < 0) {
         if (-rv == EINPROGRESS && --retries) {
 #ifdef HAVE_SANLOCK_INQ_LOCKSPACE
             /* we have this function which blocks until lockspace change the
@@ -404,6 +419,7 @@ static int virLockManagerSanlockInit(unsigned int version,
     driver->requireLeaseForDisks = true;
     driver->hostID = 0;
     driver->autoDiskLease = false;
+    driver->io_timeout = 0;
     driver->user = (uid_t) -1;
     driver->group = (gid_t) -1;
     if (VIR_STRDUP(driver->autoDiskLeasePath, LOCALSTATEDIR "/lib/libvirt/sanlock") < 0) {
index e5566efec8f99ea285fdb800eb4a3eb9676f96dc..3a1a51c5f947c4d1449e275962800214ab8aab5a 100644 (file)
 #
 #require_lease_for_disks = 1
 
+#
+# Sanlock is able to kill qemu processes on IO timeout. By its internal
+# implementation, the current default is 80 seconds. If you need to adjust
+# the value change the following variable. Value of zero means use the
+# default sanlock timeout.
+#io_timeout = 0
+
 #
 # The combination of user and group under which the sanlock
 # daemon runs. Libvirt will chown created files (like
index ef98ea63746cda6e4c74a8d15bef91ba26702093..7f66f8192bea01890c42298b53f777d69c7def33 100644 (file)
@@ -6,5 +6,6 @@ module Test_libvirt_sanlock =
 { "disk_lease_dir" = "/var/lib/libvirt/sanlock" }
 { "host_id" = "1" }
 { "require_lease_for_disks" = "1" }
+{ "io_timeout" = "0" }
 { "user" = "root" }
 { "group" = "root" }