daemon: Add a tunable to enable automatic database priority setting
authorAmitay Isaacs <amitay@gmail.com>
Fri, 4 Jan 2013 03:32:55 +0000 (14:32 +1100)
committerMichael Adam <obnox@samba.org>
Sat, 5 Jan 2013 00:14:57 +0000 (01:14 +0100)
Samba versions 3.6.x and older do not set the database priority.
This can cause deadlock between Samba and CTDB since the locking order
of database will be different. A hack was added for automatic promotion
of priority for specific databases to avoid deadlock.  This code should
not be invoked with Samba version 4.x which correctly specifies the
priority for each database.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Michael Adam <obnox@samba.org>
doc/ctdbd.1.xml
include/ctdb_private.h
server/ctdb_lock.c
server/ctdb_tunables.c

index d192febf9609597fbfc73ae1eafb994c75a4dd02..a0cba99a49b43d4c5d4e9389e0626e43e0e6c530 100644 (file)
     detection.
     </para>
     </refsect2>
+
+    <refsect2><title>Samba3AvoidDeadlock</title>
+    <para>Default: 0</para>
+    <para>
+    Enable code that prevents deadlocks with Samba (only for Samba 3.x).
+    </para>
+    <para>
+    This should be set to 1 when using Samba version 3.x to enable special
+    code in CTDB to avoid deadlock with Samba version 3.x.  This code
+    is not required for Samba version 4.x and must not be enabled for
+    Samba 4.x.
+    </para>
+    </refsect2>
   </refsect1>
 
   <refsect1><title>LVS</title>
index 348df091aaeeb8da7e0ccd181747141813e05995..582a7677c054f9f1df9c93202527585a231fae8a 100644 (file)
@@ -137,6 +137,7 @@ struct ctdb_tunable {
        uint32_t pulldb_preallocation_size;
        uint32_t no_ip_takeover_on_disabled;
        uint32_t deadlock_timeout;
+       uint32_t samba3_hack;
 };
 
 /*
index e78f3fc15fbbae18825881736626219d90f5211f..8a2ba5cded6ffc0f951907b3fd60a860496b4761 100644 (file)
@@ -96,8 +96,12 @@ struct lock_request {
  * By default, all databases are set to priority 1. So only when priority
  * is set to 1, check for databases that need higher priority.
  */
-static bool later_db(const char *name)
+static bool later_db(struct ctdb_context *ctdb, const char *name)
 {
+       if (ctdb->tunable.samba3_hack == 0) {
+               return false;
+       }
+
        if (strstr(name, "brlock") ||
            strstr(name, "g_lock") ||
            strstr(name, "notify_onelevel") ||
@@ -120,7 +124,7 @@ int ctdb_lockall_prio(struct ctdb_context *ctdb, uint32_t priority)
                if (ctdb_db->priority != priority) {
                        continue;
                }
-               if (later_db(ctdb_db->db_name)) {
+               if (later_db(ctdb, ctdb_db->db_name)) {
                        continue;
                }
                DEBUG(DEBUG_INFO, ("locking database %s, priority:%u\n",
@@ -138,7 +142,7 @@ int ctdb_lockall_prio(struct ctdb_context *ctdb, uint32_t priority)
        }
 
        for (ctdb_db = ctdb->db_list; ctdb_db; ctdb_db = ctdb_db->next) {
-               if (!later_db(ctdb_db->db_name)) {
+               if (!later_db(ctdb, ctdb_db->db_name)) {
                        continue;
                }
                DEBUG(DEBUG_INFO, ("locking database %s, priority:%u\n",
@@ -228,7 +232,7 @@ int ctdb_lockall_mark_prio(struct ctdb_context *ctdb, uint32_t priority)
                if (ctdb_db->priority != priority) {
                        continue;
                }
-               if (later_db(ctdb_db->db_name)) {
+               if (later_db(ctdb, ctdb_db->db_name)) {
                        continue;
                }
                if (tdb_transaction_write_lock_mark(ctdb_db->ltdb->tdb) != 0) {
@@ -246,7 +250,7 @@ int ctdb_lockall_mark_prio(struct ctdb_context *ctdb, uint32_t priority)
        }
 
        for (ctdb_db = ctdb->db_list; ctdb_db; ctdb_db = ctdb_db->next) {
-               if (!later_db(ctdb_db->db_name)) {
+               if (!later_db(ctdb, ctdb_db->db_name)) {
                        continue;
                }
                if (tdb_transaction_write_lock_mark(ctdb_db->ltdb->tdb) != 0) {
index 5bd13d5687548bb18b7fff24e48ed6c5674640f1..b86d6d26631c0dd2950f0f2f34e23185a5135180 100644 (file)
@@ -86,6 +86,7 @@ static const struct {
        { "PullDBPreallocation", 10*1024*10240,  offsetof(struct ctdb_tunable, pulldb_preallocation_size), false },
        { "NoIPTakeoverOnDisabled",    0,  offsetof(struct ctdb_tunable, no_ip_takeover_on_disabled), false },
        { "DeadlockTimeout",    300, offsetof(struct ctdb_tunable, deadlock_timeout), false },
+       { "Samba3AvoidDeadlocks", 0, offsetof(struct ctdb_tunable, samba3_hack), false },
 };
 
 /*