The branch, master has been updated
       via  dbb7c550133c92292a7212bdcaaa79f399b0919b (commit)
       via  29911fa44a480c17c701528ef46919b2a962a366 (commit)
       via  80fbe9364350d42658f7f8af250ac87eb1afbc21 (commit)
       via  c660f33c3eaa1b4a2c4e951c1982979e57374ed4 (commit)
       via  6ea3212a7b177c6c06b1484cf9e8b2f4036653d9 (commit)
       via  7cde53a6cbe74b1e46f7e1bca298df82c08de866 (commit)
       via  f665e3d540c90579952e590caa5828acb581ae61 (commit)
       via  a08b6ac19506160f3fb5925ea025027dce07781d (commit)
       via  7630ca4116b476636c27407748088ea335f1a06c (commit)
       via  adc113055de98fae276f9b501aff5c03cd25ddc8 (commit)
       via  e8ea65b2713417db4a618a9f4633991cfaa93fe6 (commit)
       via  f120e40533780e02ff1cdc41cc6d3af1c4c83258 (commit)
       via  187ed83f9701c7fa8d3cc476d47c5d2a87d5c308 (commit)
       via  725239535f40ca2cca445bb5bf2e181351b330e9 (commit)
       via  d2634d72d9ca0ceeb72cbb1adc95017a234480fd (commit)
       via  2a1c933ef7c78ee071e2a640ea10941f1c12e32a (commit)
       via  a3275854812aca86032704134fdf6a129069c86a (commit)
       via  d98a861716d5f8c1f4387d21666396d3164551b3 (commit)
      from  0577ce3c68e4febf49a1ef5093e918db9d5ec636 (commit)

http://gitweb.samba.org/?p=ctdb.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit dbb7c550133c92292a7212bdcaaa79f399b0919b
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Wed May 8 23:29:55 2013 +1000

    logging: Make sure ringbuffer messages are terminated with a newline
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit 29911fa44a480c17c701528ef46919b2a962a366
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Wed May 8 16:25:30 2013 +1000

    tests: Fix output of run_tests usage

commit 80fbe9364350d42658f7f8af250ac87eb1afbc21
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Wed May 8 13:45:55 2013 +1000

    locking: Set lock helper path once
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit c660f33c3eaa1b4a2c4e951c1982979e57374ed4
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Wed May 8 10:42:08 2013 +1000

    locking: Remove functions that are not used anymore
    
    These functions were used in locking child process to do the locking.  With
    locking helper, these are not required.
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit 6ea3212a7b177c6c06b1484cf9e8b2f4036653d9
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Tue Apr 30 15:13:44 2013 +1000

    locking: Remove functions that are not used anymore
    
    These functions were used in locking child process to do the locking.  With
    locking helper, these are not required.
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit 7cde53a6cbe74b1e46f7e1bca298df82c08de866
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Tue Apr 30 15:07:49 2013 +1000

    locking: Use separate locking helper binary for locking
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit f665e3d540c90579952e590caa5828acb581ae61
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Tue Apr 30 14:32:46 2013 +1000

    locking: Create commandline arguments for locking helper
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit a08b6ac19506160f3fb5925ea025027dce07781d
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Mon Apr 22 15:36:27 2013 +1000

    locking: Add a standalone helper to lock record/db
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit 7630ca4116b476636c27407748088ea335f1a06c
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Tue Apr 30 14:14:16 2013 +1000

    locking: Use database iterator for unmarking databases
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit adc113055de98fae276f9b501aff5c03cd25ddc8
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Tue Apr 30 14:16:07 2013 +1000

    locking: Add handler function for unmarking a database
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit e8ea65b2713417db4a618a9f4633991cfaa93fe6
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Tue Apr 30 14:12:40 2013 +1000

    locking: Use database iterator for marking databases
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit f120e40533780e02ff1cdc41cc6d3af1c4c83258
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Tue Apr 30 14:07:11 2013 +1000

    locking: Add handler function for marking a database
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit 187ed83f9701c7fa8d3cc476d47c5d2a87d5c308
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Tue Apr 30 14:10:06 2013 +1000

    locking: Use database iterator for unlocking databases
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit 725239535f40ca2cca445bb5bf2e181351b330e9
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Tue Apr 30 14:06:46 2013 +1000

    locking: Add handler function for unlocking a database
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit d2634d72d9ca0ceeb72cbb1adc95017a234480fd
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Tue Apr 30 14:08:51 2013 +1000

    locking: Use database iterator for locking databases
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit 2a1c933ef7c78ee071e2a640ea10941f1c12e32a
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Tue Apr 30 14:06:27 2013 +1000

    locking: Add handler function for locking a database
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit a3275854812aca86032704134fdf6a129069c86a
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Tue Apr 30 13:23:59 2013 +1000

    locking: Refactor code to iterate over databases based on priority
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

commit d98a861716d5f8c1f4387d21666396d3164551b3
Author: Amitay Isaacs <ami...@gmail.com>
Date:   Wed May 1 12:55:22 2013 +1000

    locking: Add newline to debug logs
    
    Signed-off-by: Amitay Isaacs <ami...@gmail.com>

-----------------------------------------------------------------------

Summary of changes:
 Makefile.in                    |   10 +-
 common/ctdb_logging.c          |    6 +
 include/ctdb_private.h         |    2 -
 packaging/RPM/ctdb.spec.in     |    1 +
 server/ctdb_lock.c             |  396 ++++++++++++++++++++--------------------
 server/ctdb_lock_helper.c      |  148 +++++++++++++++
 tests/scripts/integration.bash |    1 +
 tests/scripts/run_tests        |    4 +-
 8 files changed, 361 insertions(+), 207 deletions(-)
 create mode 100644 server/ctdb_lock_helper.c


Changeset truncated at 500 lines:

diff --git a/Makefile.in b/Makefile.in
index 9f94aee..1bbec6f 100755
--- a/Makefile.in
+++ b/Makefile.in
@@ -51,7 +51,7 @@ PMDA_DEST_DIR = /var/lib/pcp/pmdas
 CFLAGS=@CPPFLAGS@ -g -I$(srcdir)/include -Iinclude -Ilib -Ilib/util 
-I$(srcdir) \
        $(TALLOC_CFLAGS) $(TEVENT_CFLAGS) $(TDB_CFLAGS) -I@libreplacedir@ \
        -DVARDIR=\"$(localstatedir)\" -DETCDIR=\"$(etcdir)\" \
-       -DLOGDIR=\"$(logdir)\" \
+       -DLOGDIR=\"$(logdir)\" -DBINDIR=\"$(bindir)\" \
        -DSOCKPATH=\"$(sockpath)\" \
        -DUSE_MMAP=1 -DTEVENT_DEPRECATED_QUIET=1 @CFLAGS@ 
-Wno-format-zero-length $(POPT_CFLAGS) \
        -fPIC
@@ -107,7 +107,8 @@ TEST_BINS=tests/bin/ctdb_bench tests/bin/ctdb_fetch 
tests/bin/ctdb_fetch_one \
        tests/bin/ctdb_porting_tests \
        @INFINIBAND_BINS@
 
-BINS = bin/ctdb @CTDB_SCSI_IO@ bin/smnotify bin/ping_pong bin/ltdbtool 
@CTDB_PMDA@
+BINS = bin/ctdb @CTDB_SCSI_IO@ bin/smnotify bin/ping_pong bin/ltdbtool \
+       bin/ctdb_lock_helper @CTDB_PMDA@
 
 SBINS = bin/ctdbd
 
@@ -176,6 +177,10 @@ bin/ltdbtool: tools/ltdbtool.o $(TDB_OBJ)
        @echo Linking $@
        @$(CC) $(CFLAGS) -o $@ $+ $(TDB_LIBS) $(LIB_FLAGS)
 
+bin/ctdb_lock_helper: server/ctdb_lock_helper.o lib/util/util_file.o 
$(TALLOC_OBJ) $(TDB_OBJ)
+       @echo Linking $@
+       @$(CC) $(CFLAGS) -o $@ $+ $(TDB_LIBS) $(LIB_FLAGS)
+
 bin/smnotify: utils/smnotify/gen_xdr.o utils/smnotify/gen_smnotify.o 
utils/smnotify/smnotify.o $(POPT_OBJ)
        @echo Linking $@
        @$(CC) $(CFLAGS) -o $@ utils/smnotify/smnotify.o 
utils/smnotify/gen_xdr.o utils/smnotify/gen_smnotify.o $(POPT_OBJ) $(LIB_FLAGS)
@@ -327,6 +332,7 @@ install: all manpages $(PMDA_INSTALL)
        ${INSTALLCMD} -m 755 bin/smnotify $(DESTDIR)$(bindir)
        $(INSTALLCMD) -m 755 bin/ping_pong $(DESTDIR)$(bindir)
        $(INSTALLCMD) -m 755 bin/ltdbtool $(DESTDIR)$(bindir)
+       $(INSTALLCMD) -m 755 bin/ctdb_lock_helper $(DESTDIR)$(bindir)
        $(INSTALLCMD) -m 755 libctdb/libctdb.a $(DESTDIR)$(libdir)
        ${INSTALLCMD} -m 644 include/ctdb.h $(DESTDIR)$(includedir)
        ${INSTALLCMD} -m 644 include/ctdb_client.h $(DESTDIR)$(includedir)
diff --git a/common/ctdb_logging.c b/common/ctdb_logging.c
index 339198b..408fda8 100644
--- a/common/ctdb_logging.c
+++ b/common/ctdb_logging.c
@@ -67,6 +67,12 @@ static void log_ringbuffer_v(const char *format, va_list ap)
        if (ret == -1) {
                return;
        }
+       /* Log messages longer than MAX_LOG_SIZE are truncated to MAX_LOG_SIZE-1
+        * bytes.  In that case, add a newline.
+        */
+       if (ret >= MAX_LOG_SIZE) {
+               log_entries[next_entry].message[MAX_LOG_SIZE-2] = '\n';
+       }
 
        log_entries[next_entry].level = this_log_level;
        log_entries[next_entry].t = timeval_current();
diff --git a/include/ctdb_private.h b/include/ctdb_private.h
index 813a5a6..c47210e 100644
--- a/include/ctdb_private.h
+++ b/include/ctdb_private.h
@@ -1564,8 +1564,6 @@ int ctdb_start_monitoring_interfaces(struct ctdb_context 
*ctdb);
 /* from server/ctdb_lock.c */
 struct lock_request;
 
-int ctdb_lockall_prio(struct ctdb_context *ctdb, uint32_t priority);
-int ctdb_unlockall_prio(struct ctdb_context *ctdb, uint32_t priority);
 int ctdb_lockall_mark_prio(struct ctdb_context *ctdb, uint32_t priority);
 int ctdb_lockall_unmark_prio(struct ctdb_context *ctdb, uint32_t priority);
 
diff --git a/packaging/RPM/ctdb.spec.in b/packaging/RPM/ctdb.spec.in
index 910b59a..9872427 100644
--- a/packaging/RPM/ctdb.spec.in
+++ b/packaging/RPM/ctdb.spec.in
@@ -166,6 +166,7 @@ rm -rf $RPM_BUILD_ROOT
 %{_sysconfdir}/ctdb/notify.d/README
 %{_sbindir}/ctdbd
 %{_bindir}/ctdb
+%{_bindir}/ctdb_lock_helper
 %{_bindir}/smnotify
 %{_bindir}/ping_pong
 %{_bindir}/ltdbtool
diff --git a/server/ctdb_lock.c b/server/ctdb_lock.c
index 8a2ba5c..77b4da8 100644
--- a/server/ctdb_lock.c
+++ b/server/ctdb_lock.c
@@ -113,12 +113,15 @@ static bool later_db(struct ctdb_context *ctdb, const 
char *name)
        return false;
 }
 
-/*
- * lock all databases
- */
-int ctdb_lockall_prio(struct ctdb_context *ctdb, uint32_t priority)
+typedef int (*db_handler_t)(struct ctdb_db_context *ctdb_db,
+                           uint32_t priority,
+                           void *private_data);
+
+static int ctdb_db_iterator(struct ctdb_context *ctdb, uint32_t priority,
+                           db_handler_t handler, void *private_data)
 {
        struct ctdb_db_context *ctdb_db;
+       int ret;
 
        for (ctdb_db = ctdb->db_list; ctdb_db; ctdb_db = ctdb_db->next) {
                if (ctdb_db->priority != priority) {
@@ -127,11 +130,8 @@ int ctdb_lockall_prio(struct ctdb_context *ctdb, uint32_t 
priority)
                if (later_db(ctdb, ctdb_db->db_name)) {
                        continue;
                }
-               DEBUG(DEBUG_INFO, ("locking database %s, priority:%u\n",
-                                  ctdb_db->db_name, priority));
-               if (tdb_lockall(ctdb_db->ltdb->tdb) != 0) {
-                       DEBUG(DEBUG_ERR, ("Failed to lock database %s\n",
-                                         ctdb_db->db_name));
+               ret = handler(ctdb_db, priority, private_data);
+               if (ret != 0) {
                        return -1;
                }
        }
@@ -145,24 +145,8 @@ int ctdb_lockall_prio(struct ctdb_context *ctdb, uint32_t 
priority)
                if (!later_db(ctdb, ctdb_db->db_name)) {
                        continue;
                }
-               DEBUG(DEBUG_INFO, ("locking database %s, priority:%u\n",
-                                  ctdb_db->db_name, priority));
-               if (tdb_lockall(ctdb_db->ltdb->tdb) != 0) {
-                       DEBUG(DEBUG_ERR, ("Failed to lock database %s\n",
-                                         ctdb_db->db_name));
-                       return -1;
-               }
-       }
-
-       return 0;
-}
-
-static int ctdb_lockall(struct ctdb_context *ctdb)
-{
-       uint32_t priority;
-
-       for (priority=1; priority<=NUM_DB_PRIORITIES; priority++) {
-               if (ctdb_lockall_prio(ctdb, priority) != 0) {
+               ret = handler(ctdb_db, priority, private_data);
+               if (ret != 0) {
                        return -1;
                }
        }
@@ -172,50 +156,33 @@ static int ctdb_lockall(struct ctdb_context *ctdb)
 
 
 /*
- * unlock all databases
+ * lock all databases - mark only
  */
-int ctdb_unlockall_prio(struct ctdb_context *ctdb, uint32_t priority)
+static int db_lock_mark_handler(struct ctdb_db_context *ctdb_db, uint32_t 
priority,
+                               void *private_data)
 {
-       struct ctdb_db_context *ctdb_db;
-
-       for (ctdb_db = ctdb->db_list; ctdb_db; ctdb_db = ctdb_db->next) {
-               if (ctdb_db->priority != priority) {
-                       continue;
-               }
-               DEBUG(DEBUG_INFO, ("unlocking database %s, priority:%u\n",
-                                  ctdb_db->db_name, priority));
-               if (tdb_unlockall(ctdb_db->ltdb->tdb) != 0) {
-                       DEBUG(DEBUG_ERR, ("Failed to unlock database %s\n",
-                                         ctdb_db->db_name));
-                       return -1;
-               }
-       }
+       int tdb_transaction_write_lock_mark(struct tdb_context *);
 
-       return 0;
-}
+       DEBUG(DEBUG_INFO, ("marking locked database %s, priority:%u\n",
+                          ctdb_db->db_name, priority));
 
-static int ctdb_unlockall(struct ctdb_context *ctdb)
-{
-       uint32_t priority;
+       if (tdb_transaction_write_lock_mark(ctdb_db->ltdb->tdb) != 0) {
+               DEBUG(DEBUG_ERR, ("Failed to mark (transaction lock) database 
%s\n",
+                                 ctdb_db->db_name));
+               return -1;
+       }
 
-       for (priority=NUM_DB_PRIORITIES; priority>=0; priority--) {
-               if (ctdb_unlockall_prio(ctdb, priority) != 0) {
-                       return -1;
-               }
+       if (tdb_lockall_mark(ctdb_db->ltdb->tdb) != 0) {
+               DEBUG(DEBUG_ERR, ("Failed to mark (all lock) database %s\n",
+                                 ctdb_db->db_name));
+               return -1;
        }
 
        return 0;
 }
 
-
-/*
- * lock all databases - mark only
- */
 int ctdb_lockall_mark_prio(struct ctdb_context *ctdb, uint32_t priority)
 {
-       struct ctdb_db_context *ctdb_db;
-       int tdb_transaction_write_lock_mark(struct tdb_context *);
-
        /*
         * This function is only used by the main dameon during recovery.
         * At this stage, the databases have already been locked, by a
@@ -228,41 +195,7 @@ int ctdb_lockall_mark_prio(struct ctdb_context *ctdb, 
uint32_t priority)
                return -1;
        }
 
-       for (ctdb_db = ctdb->db_list; ctdb_db; ctdb_db = ctdb_db->next) {
-               if (ctdb_db->priority != priority) {
-                       continue;
-               }
-               if (later_db(ctdb, ctdb_db->db_name)) {
-                       continue;
-               }
-               if (tdb_transaction_write_lock_mark(ctdb_db->ltdb->tdb) != 0) {
-                       return -1;
-               }
-               if (tdb_lockall_mark(ctdb_db->ltdb->tdb) != 0) {
-                       /* FIXME: Shouldn't we unmark here? */
-                       return -1;
-               }
-       }
-
-       /* If priority != 1, later_db check is not required and can return */
-       if (priority != 1) {
-               return 0;
-       }
-
-       for (ctdb_db = ctdb->db_list; ctdb_db; ctdb_db = ctdb_db->next) {
-               if (!later_db(ctdb, ctdb_db->db_name)) {
-                       continue;
-               }
-               if (tdb_transaction_write_lock_mark(ctdb_db->ltdb->tdb) != 0) {
-                       return -1;
-               }
-               if (tdb_lockall_mark(ctdb_db->ltdb->tdb) != 0) {
-                       /* FIXME: Shouldn't we unmark here? */
-                       return -1;
-               }
-       }
-
-       return 0;
+       return ctdb_db_iterator(ctdb, priority, db_lock_mark_handler, NULL);
 }
 
 static int ctdb_lockall_mark(struct ctdb_context *ctdb)
@@ -270,7 +203,7 @@ static int ctdb_lockall_mark(struct ctdb_context *ctdb)
        uint32_t priority;
 
        for (priority=1; priority<=NUM_DB_PRIORITIES; priority++) {
-               if (ctdb_lockall_mark_prio(ctdb, priority) != 0) {
+               if (ctdb_db_iterator(ctdb, priority, db_lock_mark_handler, 
NULL) != 0) {
                        return -1;
                }
        }
@@ -282,11 +215,31 @@ static int ctdb_lockall_mark(struct ctdb_context *ctdb)
 /*
  * lock all databases - unmark only
  */
-int ctdb_lockall_unmark_prio(struct ctdb_context *ctdb, uint32_t priority)
+static int db_lock_unmark_handler(struct ctdb_db_context *ctdb_db, uint32_t 
priority,
+                                 void *private_data)
 {
-       struct ctdb_db_context *ctdb_db;
        int tdb_transaction_write_lock_unmark(struct tdb_context *);
 
+       DEBUG(DEBUG_INFO, ("unmarking locked database %s, priority:%u\n",
+                          ctdb_db->db_name, priority));
+
+       if (tdb_transaction_write_lock_unmark(ctdb_db->ltdb->tdb) != 0) {
+               DEBUG(DEBUG_ERR, ("Failed to unmark (transaction lock) database 
%s\n",
+                                 ctdb_db->db_name));
+               return -1;
+       }
+
+       if (tdb_lockall_unmark(ctdb_db->ltdb->tdb) != 0) {
+               DEBUG(DEBUG_ERR, ("Failed to unmark (all lock) database %s\n",
+                                 ctdb_db->db_name));
+               return -1;
+       }
+
+       return 0;
+}
+
+int ctdb_lockall_unmark_prio(struct ctdb_context *ctdb, uint32_t priority)
+{
        /*
         * This function is only used by the main dameon during recovery.
         * At this stage, the databases have already been locked, by a
@@ -299,19 +252,7 @@ int ctdb_lockall_unmark_prio(struct ctdb_context *ctdb, 
uint32_t priority)
                return -1;
        }
 
-       for (ctdb_db = ctdb->db_list; ctdb_db; ctdb_db = ctdb_db->next) {
-               if (ctdb_db->priority != priority) {
-                       continue;
-               }
-               if (tdb_transaction_write_lock_unmark(ctdb_db->ltdb->tdb) != 0) 
{
-                       return -1;
-               }
-               if (tdb_lockall_unmark(ctdb_db->ltdb->tdb) != 0) {
-                       return -1;
-               }
-       }
-
-       return 0;
+       return ctdb_db_iterator(ctdb, priority, db_lock_unmark_handler, NULL);
 }
 
 static int ctdb_lockall_unmark(struct ctdb_context *ctdb)
@@ -319,7 +260,7 @@ static int ctdb_lockall_unmark(struct ctdb_context *ctdb)
        uint32_t priority;
 
        for (priority=NUM_DB_PRIORITIES; priority>=0; priority--) {
-               if (ctdb_lockall_unmark_prio(ctdb, priority) != 0) {
+               if (ctdb_db_iterator(ctdb, priority, db_lock_unmark_handler, 
NULL) != 0) {
                        return -1;
                }
        }
@@ -328,68 +269,6 @@ static int ctdb_lockall_unmark(struct ctdb_context *ctdb)
 }
 
 
-/*
- * Lock record / db depending on lock_ctx->type
- * Called from child context.
- */
-static bool ctdb_lock_item(struct lock_context *lock_ctx)
-{
-       bool status = false;
-
-       switch (lock_ctx->type) {
-       case LOCK_RECORD:
-               if (tdb_chainlock(lock_ctx->ctdb_db->ltdb->tdb, lock_ctx->key) 
== 0) {
-                       status = true;
-               }
-               break;
-
-       case LOCK_DB:
-               if (tdb_lockall(lock_ctx->ctdb_db->ltdb->tdb) == 0) {
-                       status = true;
-               }
-               break;
-
-       case LOCK_ALLDB_PRIO:
-               if (ctdb_lockall_prio(lock_ctx->ctdb, lock_ctx->priority) == 0) 
{
-                       status = true;
-               }
-               break;
-
-       case LOCK_ALLDB:
-               if (ctdb_lockall(lock_ctx->ctdb) == 0) {
-                       status = true;
-               }
-               break;
-       }
-
-       return status;
-}
-
-
-/*
- * Unlock record / db depending on lock_ctx->type
- */
-void ctdb_unlock_item(struct lock_context *lock_ctx)
-{
-       switch (lock_ctx->type) {
-       case LOCK_RECORD:
-               tdb_chainunlock(lock_ctx->ctdb_db->ltdb->tdb, lock_ctx->key);
-               break;
-
-       case LOCK_DB:
-               tdb_unlockall(lock_ctx->ctdb_db->ltdb->tdb);
-               break;
-
-       case LOCK_ALLDB_PRIO:
-               ctdb_unlockall_prio(lock_ctx->ctdb, lock_ctx->priority);
-               break;
-
-       case LOCK_ALLDB:
-               ctdb_unlockall(lock_ctx->ctdb);
-               break;
-       }
-}
-
 static void ctdb_lock_schedule(struct ctdb_context *ctdb);
 
 /*
@@ -631,32 +510,118 @@ static void ctdb_lock_timeout_handler(struct 
tevent_context *ev,
 }
 
 
-static char *lock_child_log_prefix(struct lock_context *lock_ctx)
+static int db_count_handler(struct ctdb_db_context *ctdb_db, uint32_t priority,
+                           void *private_data)
 {
-       char *prefix;
-       pid_t pid;
+       int *count = (int *)private_data;
+
+       (*count)++;
+
+       return 0;
+}
+
+struct db_namelist {
+       char **names;
+       int n;
+};
+
+static int db_name_handler(struct ctdb_db_context *ctdb_db, uint32_t priority,
+                          void *private_data)
+{
+       struct db_namelist *list = (struct db_namelist *)private_data;
+
+       list->names[list->n] = talloc_strdup(list->names, ctdb_db->db_path);
+       list->n++;
+
+       return 0;
+}
+
+static char **lock_helper_args(TALLOC_CTX *mem_ctx, struct lock_context 
*lock_ctx, int fd)
+{
+       struct ctdb_context *ctdb = lock_ctx->ctdb;
+       char **args = NULL;
+       int nargs, i;
+       int priority;
+       struct db_namelist list;
+
+       switch (lock_ctx->type) {
+       case LOCK_RECORD:
+               nargs = 6;
+               break;
+
+       case LOCK_DB:
+               nargs = 5;
+               break;
+
+       case LOCK_ALLDB_PRIO:
+               nargs = 4;
+               ctdb_db_iterator(ctdb, lock_ctx->priority, db_count_handler, 
&nargs);
+               break;
+
+       case LOCK_ALLDB:
+               nargs = 4;
+               for (priority=1; priority<NUM_DB_PRIORITIES; priority++) {
+                       ctdb_db_iterator(ctdb, priority, db_count_handler, 
&nargs);
+               }
+               break;
+       }
+
+       /* Add extra argument for null termination */
+       nargs++;
+
+       args = talloc_array(mem_ctx, char *, nargs);
+       if (args == NULL) {
+               return NULL;
+       }
 
-       pid = getpid();
+       args[0] = talloc_strdup(args, "ctdb_lock_helper");
+       args[1] = talloc_asprintf(args, "%d", getpid());
+       args[2] = talloc_asprintf(args, "%d", fd);
 
        switch (lock_ctx->type) {
        case LOCK_RECORD:
-               prefix = talloc_asprintf(NULL, "lockR(%d): ", pid);
+               args[3] = talloc_strdup(args, "RECORD");
+               args[4] = talloc_strdup(args, lock_ctx->ctdb_db->db_path);
+               if (lock_ctx->key.dsize == 0) {
+                       args[5] = talloc_strdup(args, "NULL");
+               } else {
+                       args[5] = hex_encode_talloc(args, lock_ctx->key.dptr, 
lock_ctx->key.dsize);
+               }
                break;
 
        case LOCK_DB:
-               prefix = talloc_asprintf(NULL, "lockD(%d): ", pid);
+               args[3] = talloc_strdup(args, "DB");
+               args[4] = talloc_strdup(args, lock_ctx->ctdb_db->db_path);
                break;
 
        case LOCK_ALLDB_PRIO:
-               prefix = talloc_asprintf(NULL, "lockP(%d): ", pid);
+               args[3] = talloc_strdup(args, "DB");
+               list.names = args;
+               list.n = 4;
+               ctdb_db_iterator(ctdb, lock_ctx->priority, db_name_handler, 
&list);


-- 
CTDB repository

Reply via email to