Merge commit 'rusty/libctdb-new' into foo
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 17 Aug 2010 23:53:52 +0000 (09:53 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 17 Aug 2010 23:53:52 +0000 (09:53 +1000)
1  2 
Makefile.in
include/ctdb.h
tools/ctdb.c

diff --combined Makefile.in
index 15231b6c8c0ec6ea0e357719da1e4a026fa30a82,a039a08259a15853bbb78d9b8d332aabf2d57d58..8df8ff2a462d86db08695f8df35d862f3513fea1
@@@ -9,14 -9,14 +9,14 @@@ prefix = @prefix
  exec_prefix = @exec_prefix@
  datarootdir = @datarootdir@
  includedir = @includedir@
 -docdir = /usr/share/doc
 +docdir = @docdir@
  libdir = @libdir@
  bindir = @bindir@
  sbindir = @sbindir@
  mandir = @mandir@
  localstatedir = @localstatedir@
  logdir = @LOGDIR@
- VPATH = @srcdir@:@tdbdir@:@tallocdir@:@libreplacedir@:@poptdir@
+ VPATH = @srcdir@:@tdbdir@:@tallocdir@:@libreplacedir@:@poptdir@:@teventdir@:
  srcdir = @srcdir@
  etcdir = @sysconfdir@
  builddir = @builddir@
@@@ -54,7 -54,7 +54,7 @@@ CTDB_TCP_OBJ = tcp/tcp_connect.o tcp/tc
  
  CTDB_CLIENT_OBJ = client/ctdb_client.o \
        $(CTDB_COMMON_OBJ) $(POPT_OBJ) $(UTIL_OBJ) @TALLOC_OBJ@ @TDB_OBJ@ \
-       @LIBREPLACEOBJ@ $(EXTRA_OBJ) @EVENTS_OBJ@ 
+       @LIBREPLACEOBJ@ $(EXTRA_OBJ) @TEVENT_OBJ@
  
  CTDB_SERVER_OBJ = server/ctdbd.o server/ctdb_daemon.o server/ctdb_lockwait.o \
        server/ctdb_recoverd.o server/ctdb_recover.o server/ctdb_freeze.o \
diff --combined include/ctdb.h
index 13e64480cbdaea7732422ac0501b095588bbb0ce,ef13b9f95f4e59c53b50d5d09f1229009a8cc266..95376ce77281d09e63e3001061b3888155956e9a
@@@ -72,7 -72,7 +72,7 @@@ typedef void (*ctdb_log_fn_t)(void *log
   * @log: the logging function
   * @log_priv: the private argument to the logging function.
   *
-  * Returns a ctdb context if successful or NULL.  Use ctdb_free() to
+  * Returns a ctdb context if successful or NULL.  Use ctdb_disconnect() to
   * release the returned ctdb_connection when finished.
   *
   * See Also:
@@@ -100,6 -100,14 +100,14 @@@ void ctdb_log_file(FILE *, int, const c
   */
  extern int ctdb_log_level;
  
+ /**
+  * ctdb_disconnect - close down a connection to ctdbd.
+  * @ctdb: the ctdb connectio returned from ctdb_connect.
+  *
+  * The @ctdb arg will be freed by this call, and must not be used again.
+  */
+ void ctdb_disconnect(struct ctdb_connection *ctdb);
  /***
   *
   *  Asynchronous API
@@@ -177,7 -185,7 +185,7 @@@ void ctdb_request_free(struct ctdb_conn
   * actual private parameter.
   */
  typedef void (*ctdb_callback_t)(struct ctdb_connection *ctdb,
 -                              struct ctdb_request *req, void *private);
 +                              struct ctdb_request *req, void *private_data);
  
  /**
   * struct ctdb_db - connection to a particular open TDB
   * This represents a particular open database: you receive it from
   * ctdb_attachdb or ctdb_attachdb_recv to manipulate a database.
   *
-  * You have to free the handle with ctdb_detach_db() when finished with it.
+  * You have to free the handle with ctdb_detachdb() when finished with it.
   */
  struct ctdb_db;
  
@@@ -247,7 -255,7 +255,7 @@@ struct ctdb_lock
  typedef void (*ctdb_rrl_callback_t)(struct ctdb_db *ctdb_db,
                                    struct ctdb_lock *lock,
                                    TDB_DATA data,
 -                                  void *private);
 +                                  void *private_data);
  
  /**
   * ctdb_readrecordlock_async - read and lock a record
@@@ -299,8 -307,9 +307,9 @@@ typedef void (*ctdb_message_fn_t)(struc
   * @ctdb: the ctdb_connection from ctdb_connect.
   * @srvid: the 64 bit identifier for our messages.
   * @handler: the callback when we receive such a message (typesafe)
+  * @handler_data: the argument to handler()
   * @callback: the callback when ctdb replies to our message (typesafe)
-  * @cbdata: the argument to callback() and handler()
+  * @cbdata: the argument to callback()
   *
   * Note: our callback will always be called before handler.
   *
  struct ctdb_request *
  ctdb_set_message_handler_send(struct ctdb_connection *ctdb, uint64_t srvid,
                              ctdb_message_fn_t handler,
+                             void *handler_data,
                              ctdb_callback_t callback,
                              void *cbdata);
  
@@@ -328,6 -338,8 +338,8 @@@ bool ctdb_set_message_handler_recv(stru
   * ctdb_remove_message_handler_send - unregister for messages to a srvid
   * @ctdb: the ctdb_connection from ctdb_connect.
   * @srvid: the 64 bit identifier for our messages.
+  * @handler: the callback when we receive such a message (typesafe)
+  * @handler_data: the argument to handler()
   * @callback: the callback when ctdb replies to our message (typesafe)
   * @cbdata: the argument to callback()
   *
   */
  struct ctdb_request *
  ctdb_remove_message_handler_send(struct ctdb_connection *ctdb, uint64_t srvid,
+                                ctdb_message_fn_t handler, void *handler_data,
                                 ctdb_callback_t callback, void *cbdata);
  
  /**
   * After this returns true, the registered handler will no longer be called.
   * If this returns false, the de-registration failed.
   */
- bool ctdb_remove_message_handler_recv(struct ctdb_request *handle);
+ bool ctdb_remove_message_handler_recv(struct ctdb_connection *ctdb,
+                                     struct ctdb_request *req);
  
  
  /**
@@@ -456,8 -470,18 +470,18 @@@ struct ctdb_db *ctdb_attachdb(struct ct
                              const char *name, bool persistent,
                              uint32_t tdb_flags);
  
+ /**
+  * ctdb_detachdb - close a clustered TDB.
+  * @ctdb: the ctdb_connection from ctdb_connect.
+  * @db: the database from ctdb_attachdb/ctdb_attachdb_send
+  *
+  * Closes a clustered tdb.
+  */
+ void ctdb_detachdb(struct ctdb_connection *ctdb, struct ctdb_db *db);
  /**
   * ctdb_readrecordlock - read and lock a record (synchronous)
+  * @ctdb: the ctdb_connection from ctdb_connect.
   * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
   * @key: the key of the record to lock.
   * @req: a pointer to the request, if one is needed.
   * Do a ctdb_readrecordlock_send and wait for it to complete.
   * Returns NULL on failure.
   */
- struct ctdb_lock *ctdb_readrecordlock(struct ctdb_db *ctdb_db, TDB_DATA key,
+ struct ctdb_lock *ctdb_readrecordlock(struct ctdb_connection *ctdb,
+                                     struct ctdb_db *ctdb_db, TDB_DATA key,
                                      TDB_DATA *data);
  
  
   * failed.
   */
  bool ctdb_set_message_handler(struct ctdb_connection *ctdb, uint64_t srvid,
-                            ctdb_message_fn_t handler, void *cbdata);
+                             ctdb_message_fn_t handler, void *cbdata);
  
  
  /**
   * ctdb_remove_message_handler - deregister for messages (synchronous)
   * @ctdb: the ctdb_connection from ctdb_connect.
   * @srvid: the 64 bit identifier for our messages.
+  * @handler: the callback when we receive such a message (typesafe)
+  * @handler_data: the argument to handler()
   *
   * If this returns true, the message handler will no longer be called.
   * If this returns false, the deregistration failed.
   */
- bool ctdb_remove_message_handler(struct ctdb_connection *ctdb, uint64_t srvid);
+ bool ctdb_remove_message_handler(struct ctdb_connection *ctdb, uint64_t srvid,
+                                ctdb_message_fn_t handler, void *handler_data);
  
  /**
   * ctdb_getpnn - read the pnn number of a node (synchronous)
@@@ -533,12 -561,23 +561,23 @@@ bool ctdb_getrecmaster(struct ctdb_conn
         typesafe_cb_preargs(void, (cb), (cbdata),                      \
                             struct ctdb_connection *, struct ctdb_request *)
  
+ #define ctdb_msgcb(cb, cbdata)                                                \
+       typesafe_cb_preargs(void, (cb), (cbdata),                       \
+                           struct ctdb_connection *, uint64_t, TDB_DATA)
  #define ctdb_connect(addr, log, logpriv)                              \
        ctdb_connect((addr),                                            \
                     typesafe_cb_postargs(void, (log), (logpriv),       \
                                          int, const char *, va_list),  \
                     (logpriv))
  
+ #define ctdb_set_message_handler(ctdb, srvid, handler, hdata)         \
+       ctdb_set_message_handler((ctdb), (srvid),                       \
+                                ctdb_msgcb((handler), (hdata)), (hdata))
+ #define ctdb_remove_message_handler(ctdb, srvid, handler, hdata)      \
+       ctdb_remove_message_handler((ctdb), (srvid),                    \
+                                   ctdb_msgcb((handler), (hdata)), (hdata))
  
  #define ctdb_attachdb_send(ctdb, name, persistent, tdb_flags, cb, cbdata) \
        ctdb_attachdb_send((ctdb), (name), (persistent), (tdb_flags),   \
                                    struct ctdb_db *, struct ctdb_lock *, \
                                    TDB_DATA), (cbdata))
  
- #define ctdb_set_message_handler_send(ctdb, srvid, handler, cb, cbdata)       \
-       ctdb_set_message_handler_send((ctdb), (srvid), (handler),       \
-             ctdb_sendcb((cb), (cbdata)), (cbdata))
+ #define ctdb_set_message_handler_send(ctdb, srvid, handler, hdata, cb, cbdata) \
+       ctdb_set_message_handler_send((ctdb), (srvid),                  \
+                                     ctdb_msgcb((handler), (hdata)), (hdata), \
+                                     ctdb_sendcb((cb), (cbdata)), (cbdata))
  
- #define ctdb_remove_message_handler_send(ctdb, srvid, cb, cbdata)     \
+ #define ctdb_remove_message_handler_send(ctdb, srvid, handler, hdata, cb, cbdata) \
        ctdb_remove_message_handler_send((ctdb), (srvid),               \
+             ctdb_msgcb((handler), (hdata)), (hdata),                  \
              ctdb_sendcb((cb), (cbdata)), (cbdata))
  
  #define ctdb_getpnn_send(ctdb, destnode, cb, cbdata)                  \
diff --combined tools/ctdb.c
index 76d1febaf2840c5fda5b48819ed1508798263f77,deb99a54f3573ff8597c3f3df967b06cee9b5a10..e915e0099ddc3b9dee0ab72bff9ecc28acc175b4
@@@ -19,7 -19,7 +19,7 @@@
  */
  
  #include "includes.h"
- #include "lib/events/events.h"
+ #include "lib/tevent/tevent.h"
  #include "system/time.h"
  #include "system/filesys.h"
  #include "system/network.h"
@@@ -97,7 -97,7 +97,7 @@@ static void verify_node(struct ctdb_con
        /* verify we can access the node */
        ret = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn);
        if (ret == -1) {
 -              DEBUG(DEBUG_ERR,("Can not ban node. Node is not operational.\n"));
 +              DEBUG(DEBUG_ERR,("Can not access node. Node is not operational.\n"));
                exit(10);
        }
  }
@@@ -3272,6 -3272,28 +3272,6 @@@ static int control_setdebug(struct ctdb
  }
  
  
 -/*
 -  freeze a node
 - */
 -static int control_freeze(struct ctdb_context *ctdb, int argc, const char **argv)
 -{
 -      int ret;
 -      uint32_t priority;
 -      
 -      if (argc == 1) {
 -              priority = strtol(argv[0], NULL, 0);
 -      } else {
 -              priority = 0;
 -      }
 -      DEBUG(DEBUG_ERR,("Freeze by priority %u\n", priority));
 -
 -      ret = ctdb_ctrl_freeze_priority(ctdb, TIMELIMIT(), options.pnn, priority);
 -      if (ret != 0) {
 -              DEBUG(DEBUG_ERR, ("Unable to freeze node %u\n", options.pnn));
 -      }               
 -      return 0;
 -}
 -
  /*
    thaw a node
   */
@@@ -4378,8 -4400,8 +4378,8 @@@ static const struct 
        { "showban",         control_showban,           true,   false,  "show ban information"},
        { "shutdown",        control_shutdown,          true,   false,  "shutdown ctdbd" },
        { "recover",         control_recover,           true,   false,  "force recovery" },
 +      { "sync",            control_ipreallocate,      true,   false,  "wait until ctdbd has synced all state changes" },
        { "ipreallocate",    control_ipreallocate,      true,   false,  "force the recovery daemon to perform a ip reallocation procedure" },
 -      { "freeze",          control_freeze,            true,   false,  "freeze databases", "[priority:1-3]" },
        { "thaw",            control_thaw,              true,   false,  "thaw databases", "[priority:1-3]" },
        { "isnotrecmaster",  control_isnotrecmaster,    false,  false,  "check if the local node is recmaster or not" },
        { "killtcp",         kill_tcp,                  false,  false, "kill a tcp connection.", "<srcip:port> <dstip:port>" },
        { "getdbprio",        control_getdbprio,        false,  false, "Get DB priority", "<dbid>"},
        { "msglisten",        control_msglisten,        false,  false, "Listen on a srvid port for messages", "<msg srvid>"},
        { "msgsend",          control_msgsend,  false,  false, "Send a message to srvid", "<srvid> <message>"},
 +      { "sync",            control_ipreallocate,      true,   false,  "wait until ctdbd has synced all state changes" },
  };
  
  /*