ctdb-daemon: Rename struct ctdb_ban_time to ctdb_ban_state
[obnox/samba/samba-obnox.git] / ctdb / server / ctdb_control.c
index c73458825cd936454147c2d8d4e966694523efa2..1ba1ef796eefee21c25a32595dd915b9368baabb 100644 (file)
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
-#include "includes.h"
-#include "lib/tevent/tevent.h"
-#include "lib/tdb/include/tdb.h"
+#include "replace.h"
 #include "system/network.h"
 #include "system/filesys.h"
 #include "system/wait.h"
-#include "../include/ctdb_private.h"
+
+#include <talloc.h>
+#include <tevent.h>
+
+#include "lib/tdb_wrap/tdb_wrap.h"
 #include "lib/util/dlinklist.h"
-#include "db_wrap.h"
+#include "lib/util/debug.h"
+#include "lib/util/samba_util.h"
+#include "lib/util/talloc_report.h"
+
+#include "ctdb_private.h"
+#include "ctdb_client.h"
+#include "ctdb_logging.h"
+
+#include "common/reqid.h"
+#include "common/common.h"
 
 
 struct ctdb_control_state {
@@ -41,34 +52,46 @@ struct ctdb_control_state {
  */
 int32_t ctdb_dump_memory(struct ctdb_context *ctdb, TDB_DATA *outdata)
 {
-       /* dump to a file, then send the file as a blob */
-       FILE *f;
-       long fsize;
-       f = tmpfile();
-       if (f == NULL) {
-               DEBUG(DEBUG_ERR,(__location__ " Unable to open tmpfile - %s\n", strerror(errno)));
+       char *report;
+       size_t reportlen;
+
+       report = talloc_report_str(outdata, NULL);
+       if (report == NULL) {
+               DEBUG(DEBUG_ERR,
+                     (__location__ " talloc_report_str failed\n"));
                return -1;
        }
-       talloc_report_full(NULL, f);
-       fsize = ftell(f);
-       rewind(f);
-       outdata->dptr = talloc_size(outdata, fsize);
-       CTDB_NO_MEMORY(ctdb, outdata->dptr);
-       outdata->dsize = fread(outdata->dptr, 1, fsize, f);
-       fclose(f);
-       if (outdata->dsize != fsize) {
-               DEBUG(DEBUG_ERR,(__location__ " Unable to read tmpfile\n"));
-               return -1;
+       reportlen = talloc_get_size(report);
+
+       if (reportlen > 0) {
+               reportlen -= 1; /* strip trailing zero */
        }
+
+       outdata->dptr = (uint8_t *)report;
+       outdata->dsize = reportlen;
        return 0;
 }
 
+static int32_t control_not_implemented(const char *unsupported,
+                                      const char *alternate)
+{
+       if (alternate == NULL) {
+               DEBUG(DEBUG_ERR,
+                     ("Control %s is not implemented any more\n",
+                      unsupported));
+       } else {
+               DEBUG(DEBUG_ERR,
+                     ("Control %s is not implemented any more, use %s instead\n",
+                      unsupported, alternate));
+       }
+       return -1;
+}
 
 /*
   process a control request
  */
 static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb, 
-                                    struct ctdb_req_control *c,
+                                    struct ctdb_req_control_old *c,
                                     TDB_DATA indata,
                                     TDB_DATA *outdata, uint32_t srcnode,
                                     const char **errormsg,
@@ -86,27 +109,22 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
 
        case CTDB_CONTROL_SET_DEBUG: {
                CHECK_CONTROL_DATA_SIZE(sizeof(int32_t));
-               LogLevel = *(int32_t *)indata.dptr;
+               DEBUGLEVEL = *(int32_t *)indata.dptr;
                return 0;
        }
 
        case CTDB_CONTROL_GET_DEBUG: {
                CHECK_CONTROL_DATA_SIZE(0);
-               outdata->dptr = (uint8_t *)&LogLevel;
-               outdata->dsize = sizeof(LogLevel);
+               outdata->dptr = (uint8_t *)&(DEBUGLEVEL);
+               outdata->dsize = sizeof(DEBUGLEVEL);
                return 0;
        }
 
        case CTDB_CONTROL_STATISTICS: {
-               int i;
                CHECK_CONTROL_DATA_SIZE(0);
                ctdb->statistics.memory_used = talloc_total_size(NULL);
-               ctdb->statistics.frozen = 0;
-               for (i=1; i<= NUM_DB_PRIORITIES; i++) {
-                       if (ctdb->freeze_mode[i] == CTDB_FREEZE_FROZEN) {
-                               ctdb->statistics.frozen = 1;
-                       }
-               }
+               ctdb->statistics.num_clients = ctdb->num_clients;
+               ctdb->statistics.frozen = (ctdb_db_all_frozen(ctdb) ? 1 : 0);
                ctdb->statistics.recovering = (ctdb->recovery_mode == CTDB_RECOVERY_ACTIVE);
                ctdb->statistics.statistics_current_time = timeval_current();
 
@@ -128,8 +146,15 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
        }
 
        case CTDB_CONTROL_STATISTICS_RESET: {
+               struct ctdb_db_context *ctdb_db;
+
                CHECK_CONTROL_DATA_SIZE(0);
                ZERO_STRUCT(ctdb->statistics);
+               for (ctdb_db = ctdb->db_list;
+                    ctdb_db != NULL;
+                    ctdb_db = ctdb_db->next) {
+                       ctdb_db_statistics_reset(ctdb_db);
+               }
                ctdb->statistics.statistics_start_time = timeval_current();
                return 0;
        }
@@ -141,15 +166,29 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return ctdb_control_getdbmap(ctdb, opcode, indata, outdata);
 
        case CTDB_CONTROL_GET_NODEMAPv4:
-               return ctdb_control_getnodemapv4(ctdb, opcode, indata, outdata);
+               return control_not_implemented("GET_NODEMAPv4", "GET_NODEMAP");
 
        case CTDB_CONTROL_GET_NODEMAP:
                return ctdb_control_getnodemap(ctdb, opcode, indata, outdata);
 
+       case CTDB_CONTROL_GET_NODES_FILE:
+               return ctdb_control_getnodesfile(ctdb, opcode, indata, outdata);
+
        case CTDB_CONTROL_RELOAD_NODES_FILE:
                CHECK_CONTROL_DATA_SIZE(0);
                return ctdb_control_reload_nodes_file(ctdb, opcode);
 
+       case CTDB_CONTROL_SET_DB_STICKY: {
+               uint32_t db_id;
+               struct ctdb_db_context *ctdb_db;
+
+               CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
+               db_id = *(uint32_t *)indata.dptr;
+               ctdb_db = find_ctdb_db(ctdb, db_id);
+               if (ctdb_db == NULL) return -1;
+               return ctdb_set_db_sticky(ctdb, ctdb_db);
+       }
+
        case CTDB_CONTROL_SETVNNMAP:
                return ctdb_control_setvnnmap(ctdb, opcode, indata, outdata);
 
@@ -158,23 +197,13 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return ctdb_control_pull_db(ctdb, indata, outdata);
 
        case CTDB_CONTROL_SET_DMASTER: 
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_control_set_dmaster));
-               return ctdb_control_set_dmaster(ctdb, indata);
+               return control_not_implemented("SET_DMASTER", NULL);
 
        case CTDB_CONTROL_PUSH_DB:
                return ctdb_control_push_db(ctdb, indata);
 
        case CTDB_CONTROL_GET_RECMODE: {
-               int i;
-               if (ctdb->recovery_mode == CTDB_RECOVERY_ACTIVE) {
-                       return CTDB_RECOVERY_ACTIVE;
-               }                 
-               for (i=1; i<=NUM_DB_PRIORITIES; i++) {
-                       if (ctdb->freeze_mode[i] == CTDB_FREEZE_FROZEN) {
-                               return CTDB_RECOVERY_ACTIVE;
-                       }
-               }
-               return CTDB_RECOVERY_NORMAL;
+               return ctdb->recovery_mode;
        }
 
        case CTDB_CONTROL_SET_RECMASTER: {
@@ -192,7 +221,14 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
 
        case CTDB_CONTROL_PING:
                CHECK_CONTROL_DATA_SIZE(0);
-               return ctdb->statistics.num_clients;
+               return ctdb->num_clients;
+
+       case CTDB_CONTROL_GET_RUNSTATE:
+               CHECK_CONTROL_DATA_SIZE(0);
+               outdata->dptr = (uint8_t *)&ctdb->runstate;
+               outdata->dsize = sizeof(uint32_t);
+               return 0;
+
 
        case CTDB_CONTROL_SET_DB_READONLY: {
                uint32_t db_id;
@@ -236,12 +272,8 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
        case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
          return ctdb_control_db_attach(ctdb, indata, outdata, srvid, true, client_id, c, async_reply);
 
-       case CTDB_CONTROL_SET_CALL: {
-               struct ctdb_control_set_call *sc = 
-                       (struct ctdb_control_set_call *)indata.dptr;
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_control_set_call));
-               return ctdb_daemon_set_call(ctdb, sc->db_id, sc->fn, sc->id);
-       }
+       case CTDB_CONTROL_SET_CALL:
+               return control_not_implemented("SET_CALL", NULL);
 
        case CTDB_CONTROL_TRAVERSE_START:
                CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_traverse_start));
@@ -254,6 +286,9 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
        case CTDB_CONTROL_TRAVERSE_ALL:
                return ctdb_control_traverse_all(ctdb, indata, outdata);
 
+       case CTDB_CONTROL_TRAVERSE_ALL_EXT:
+               return ctdb_control_traverse_all_ext(ctdb, indata, outdata);
+
        case CTDB_CONTROL_TRAVERSE_DATA:
                return ctdb_control_traverse_data(ctdb, indata, outdata);
 
@@ -284,7 +319,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
 
        case CTDB_CONTROL_THAW:
                CHECK_CONTROL_DATA_SIZE(0);
-               return ctdb_control_thaw(ctdb, (uint32_t)c->srvid);
+               return ctdb_control_thaw(ctdb, (uint32_t)c->srvid, true);
 
        case CTDB_CONTROL_SET_RECMODE:
                CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));              
@@ -308,42 +343,39 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return 0;
 
        case CTDB_CONTROL_SHUTDOWN:
-               ctdb_stop_recoverd(ctdb);
-               ctdb_stop_keepalive(ctdb);
-               ctdb_stop_monitoring(ctdb);
-               ctdb_release_all_ips(ctdb);
-               if (ctdb->methods != NULL) {
-                       ctdb->methods->shutdown(ctdb);
-               }
-               ctdb_event_script(ctdb, CTDB_EVENT_SHUTDOWN);
-               DEBUG(DEBUG_NOTICE,("Received SHUTDOWN command. Stopping CTDB daemon.\n"));
-               exit(0);
+               DEBUG(DEBUG_NOTICE,("Received SHUTDOWN command.\n"));
+               ctdb_shutdown_sequence(ctdb, 0);
+               /* In case above returns due to duplicate shutdown */
+               return 0;
 
        case CTDB_CONTROL_TAKEOVER_IPv4:
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_public_ipv4));
-               return ctdb_control_takeover_ipv4(ctdb, c, indata, async_reply);
+               return control_not_implemented("TAKEOVER_IPv4", "TAKEOVER_IP");
 
        case CTDB_CONTROL_TAKEOVER_IP:
                CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_public_ip));
                return ctdb_control_takeover_ip(ctdb, c, indata, async_reply);
 
        case CTDB_CONTROL_RELEASE_IPv4:
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_public_ipv4));
-               return ctdb_control_release_ipv4(ctdb, c, indata, async_reply);
+               return control_not_implemented("RELEASE_IPv4", "RELEASE_IP");
 
        case CTDB_CONTROL_RELEASE_IP:
                CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_public_ip));
                return ctdb_control_release_ip(ctdb, c, indata, async_reply);
 
-       case CTDB_CONTROL_GET_PUBLIC_IPSv4:
+       case CTDB_CONTROL_IPREALLOCATED:
                CHECK_CONTROL_DATA_SIZE(0);
-               return ctdb_control_get_public_ipsv4(ctdb, c, outdata);
+               return ctdb_control_ipreallocated(ctdb, c, async_reply);
+
+       case CTDB_CONTROL_GET_PUBLIC_IPSv4:
+               return control_not_implemented("GET_PUBLIC_IPSv4",
+                                              "GET_PUBLIC_IPS");
 
        case CTDB_CONTROL_GET_PUBLIC_IPS:
                CHECK_CONTROL_DATA_SIZE(0);
                return ctdb_control_get_public_ips(ctdb, c, outdata);
 
-       case CTDB_CONTROL_TCP_CLIENT: 
+       case CTDB_CONTROL_TCP_CLIENT:
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_connection));
                return ctdb_control_tcp_client(ctdb, client_id, indata);
 
        case CTDB_CONTROL_STARTUP: 
@@ -351,15 +383,15 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return ctdb_control_startup(ctdb, srcnode);
 
        case CTDB_CONTROL_TCP_ADD: 
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_tcp_connection));
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_connection));
                return ctdb_control_tcp_add(ctdb, indata, false);
 
        case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE: 
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_tcp_connection));
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_connection));
                return ctdb_control_tcp_add(ctdb, indata, true);
 
        case CTDB_CONTROL_TCP_REMOVE: 
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_tcp_connection));
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_connection));
                return ctdb_control_tcp_remove(ctdb, indata);
 
        case CTDB_CONTROL_SET_TUNABLE:
@@ -376,7 +408,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return ctdb_control_modflags(ctdb, indata);
 
        case CTDB_CONTROL_KILL_TCP: 
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_control_killtcp));
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_connection));
                return ctdb_control_kill_tcp(ctdb, indata);
 
        case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
@@ -388,15 +420,15 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return ctdb_control_set_tcp_tickle_list(ctdb, indata);
 
        case CTDB_CONTROL_REGISTER_SERVER_ID: 
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_server_id));
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_client_id));
                return ctdb_control_register_server_id(ctdb, client_id, indata);
 
        case CTDB_CONTROL_UNREGISTER_SERVER_ID: 
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_server_id));
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_client_id));
                return ctdb_control_unregister_server_id(ctdb, indata);
 
        case CTDB_CONTROL_CHECK_SERVER_ID: 
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_server_id));
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_client_id));
                return ctdb_control_check_server_id(ctdb, indata);
 
        case CTDB_CONTROL_GET_SERVER_ID_LIST:
@@ -404,7 +436,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return ctdb_control_get_server_id_list(ctdb, outdata);
 
        case CTDB_CONTROL_PERSISTENT_STORE:
-               return ctdb_control_persistent_store(ctdb, c, indata, async_reply);
+               return control_not_implemented("PERSISTENT_STORE", NULL);
 
        case CTDB_CONTROL_UPDATE_RECORD:
                return ctdb_control_update_record(ctdb, c, indata, async_reply);
@@ -421,7 +453,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return ctdb_control_transaction_commit(ctdb, *(uint32_t *)indata.dptr);
 
        case CTDB_CONTROL_WIPE_DATABASE:
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_control_wipe_database));
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_control_transdb));
                return ctdb_control_wipe_database(ctdb, indata);
 
        case CTDB_CONTROL_UPTIME:
@@ -440,7 +472,8 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return ctdb_control_add_public_address(ctdb, indata);
 
        case CTDB_CONTROL_DEL_PUBLIC_IP:
-               return ctdb_control_del_public_address(ctdb, indata);
+               return ctdb_control_del_public_address(ctdb, c, indata,
+                                                      async_reply);
 
        case CTDB_CONTROL_GET_CAPABILITIES:
                return ctdb_control_get_capabilities(ctdb, outdata);
@@ -453,17 +486,16 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
 
        case CTDB_CONTROL_TRANS2_COMMIT:
        case CTDB_CONTROL_TRANS2_COMMIT_RETRY:
-               return ctdb_control_trans2_commit(ctdb, c, indata, async_reply);
+               return control_not_implemented("TRANS2_COMMIT", "TRANS3_COMMIT");
 
        case CTDB_CONTROL_TRANS2_ERROR:
-               return ctdb_control_trans2_error(ctdb, c);
+               return control_not_implemented("TRANS2_ERROR", NULL);
 
        case CTDB_CONTROL_TRANS2_FINISHED:
-               return ctdb_control_trans2_finished(ctdb, c);
+               return control_not_implemented("TRANS2_FINISHED", NULL);
 
        case CTDB_CONTROL_TRANS2_ACTIVE:
-               CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
-               return ctdb_control_trans2_active(ctdb, c, *(uint32_t *)indata.dptr);
+               return control_not_implemented("TRANS2_ACTIVE", NULL);
 
        case CTDB_CONTROL_TRANS3_COMMIT:
                return ctdb_control_trans3_commit(ctdb, c, indata, async_reply);
@@ -487,21 +519,40 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                        outdata->dsize = strlen(ctdb->recovery_lock_file) + 1;
                }
                return 0;
-       case CTDB_CONTROL_SET_RECLOCK_FILE:
-               ctdb->tunable.verify_recovery_lock = 0;
-               if (ctdb->recovery_lock_file != NULL) {
-                       talloc_free(ctdb->recovery_lock_file);
-                       ctdb->recovery_lock_file = NULL;
+       case CTDB_CONTROL_SET_RECLOCK_FILE: {
+               char *t;
+
+               if (indata.dsize == 0) {
+                       TALLOC_FREE(ctdb->recovery_lock_file);
+                       return 0;
                }
-               if (indata.dsize > 0) {
-                       ctdb->recovery_lock_file = talloc_strdup(ctdb, discard_const(indata.dptr));
-                       ctdb->tunable.verify_recovery_lock = 1;
+
+               /* Return silent success if unchanged.  Recovery
+                * master updates all nodes on each recovery - we
+                * don't need the extra memory allocation or log
+                * message each time. */
+               if (ctdb->recovery_lock_file != NULL &&
+                   strcmp(discard_const(indata.dptr),
+                          ctdb->recovery_lock_file) == 0) {
+                       return 0;
                }
+
+               t = talloc_strdup(ctdb, discard_const(indata.dptr));
+               if (t == NULL) {
+                       DEBUG(DEBUG_ERR, ("Out of memory in SET_RECLOCK_FILE\n"));
+                       return -1;
+               }
+
+               talloc_free(ctdb->recovery_lock_file);
+               ctdb->recovery_lock_file = t;
+               DEBUG(DEBUG_NOTICE, ("Updated recovery lock file to %s\n", t));
+
                return 0;
+       }
 
        case CTDB_CONTROL_STOP_NODE:
                CHECK_CONTROL_DATA_SIZE(0);
-               return ctdb_control_stop_node(ctdb, c, async_reply);
+               return ctdb_control_stop_node(ctdb);
 
        case CTDB_CONTROL_CONTINUE_NODE:
                CHECK_CONTROL_DATA_SIZE(0);
@@ -553,7 +604,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return ctdb_control_disable_script(ctdb, indata);
 
        case CTDB_CONTROL_SET_BAN_STATE:
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_ban_time));
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_ban_state));
                return ctdb_control_set_ban_state(ctdb, indata);
 
        case CTDB_CONTROL_GET_BAN_STATE:
@@ -562,7 +613,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
 
        case CTDB_CONTROL_SET_DB_PRIORITY:
                CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_db_priority));
-               return ctdb_control_set_db_priority(ctdb, indata);
+               return ctdb_control_set_db_priority(ctdb, indata, client_id);
 
        case CTDB_CONTROL_GET_DB_PRIORITY: {
                uint32_t db_id;
@@ -583,15 +634,14 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return ctdb_control_register_notify(ctdb, client_id, indata);
 
        case CTDB_CONTROL_DEREGISTER_NOTIFY:
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_client_notify_deregister));
+               CHECK_CONTROL_DATA_SIZE(sizeof(uint64_t));
                return ctdb_control_deregister_notify(ctdb, client_id, indata);
 
        case CTDB_CONTROL_GET_LOG:
-               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_get_log_addr));
-               return ctdb_control_get_log(ctdb, indata);
+               return control_not_implemented("GET_LOG", NULL);
 
        case CTDB_CONTROL_CLEAR_LOG:
-               return ctdb_control_clear_log(ctdb);
+               return control_not_implemented("CLEAR_LOG", NULL);
 
        case CTDB_CONTROL_GET_DB_SEQNUM:
                CHECK_CONTROL_DATA_SIZE(sizeof(uint64_t));
@@ -634,6 +684,37 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
                return ctdb_control_get_db_statistics(ctdb, *(uint32_t *)indata.dptr, outdata);
 
+       case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
+               CHECK_CONTROL_DATA_SIZE(0);
+               return ctdb_control_reload_public_ips(ctdb, c, async_reply);
+
+       case CTDB_CONTROL_RECEIVE_RECORDS:
+               return ctdb_control_receive_records(ctdb, indata, outdata);
+
+       case CTDB_CONTROL_DB_DETACH:
+               return ctdb_control_db_detach(ctdb, indata, client_id);
+
+       case CTDB_CONTROL_DB_FREEZE:
+               CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
+               return ctdb_control_db_freeze(ctdb, c, *(uint32_t *)indata.dptr,
+                                             async_reply);
+
+       case CTDB_CONTROL_DB_THAW:
+               CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
+               return ctdb_control_db_thaw(ctdb, *(uint32_t *)indata.dptr);
+
+       case CTDB_CONTROL_DB_TRANSACTION_START:
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_control_transdb));
+               return ctdb_control_db_transaction_start(ctdb, indata);
+
+       case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_control_transdb));
+               return ctdb_control_db_transaction_commit(ctdb, indata);
+
+       case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
+               CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
+               return ctdb_control_db_transaction_cancel(ctdb, indata);
+
        default:
                DEBUG(DEBUG_CRIT,(__location__ " Unknown CTDB control opcode %u\n", opcode));
                return -1;
@@ -643,10 +724,10 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
 /*
   send a reply for a ctdb control
  */
-void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control *c,
+void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_control_old *c,
                                TDB_DATA *outdata, int32_t status, const char *errormsg)
 {
-       struct ctdb_reply_control *r;
+       struct ctdb_reply_control_old *r;
        size_t len;
        
        /* some controls send no reply */
@@ -654,11 +735,11 @@ void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_contr
                return;
        }
 
-       len = offsetof(struct ctdb_reply_control, data) + (outdata?outdata->dsize:0);
+       len = offsetof(struct ctdb_reply_control_old, data) + (outdata?outdata->dsize:0);
        if (errormsg) {
                len += strlen(errormsg);
        }
-       r = ctdb_transport_allocate(ctdb, ctdb, CTDB_REPLY_CONTROL, len, struct ctdb_reply_control);
+       r = ctdb_transport_allocate(ctdb, ctdb, CTDB_REPLY_CONTROL, len, struct ctdb_reply_control_old);
        if (r == NULL) {
                DEBUG(DEBUG_ERR,(__location__ "Unable to allocate transport - OOM or transport is down\n"));
                return;
@@ -686,10 +767,10 @@ void ctdb_request_control_reply(struct ctdb_context *ctdb, struct ctdb_req_contr
 */
 void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
 {
-       struct ctdb_req_control *c = (struct ctdb_req_control *)hdr;
+       struct ctdb_req_control_old *c = (struct ctdb_req_control_old *)hdr;
        TDB_DATA data, *outdata;
        int32_t status;
-       bool async_reply = False;
+       bool async_reply = false;
        const char *errormsg = NULL;
 
        data.dptr = &c->data[0];
@@ -710,12 +791,12 @@ void ctdb_request_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr
 */
 void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
 {
-       struct ctdb_reply_control *c = (struct ctdb_reply_control *)hdr;
+       struct ctdb_reply_control_old *c = (struct ctdb_reply_control_old *)hdr;
        TDB_DATA data;
        struct ctdb_control_state *state;
        const char *errormsg = NULL;
 
-       state = ctdb_reqid_find(ctdb, hdr->reqid, struct ctdb_control_state);
+       state = reqid_find(ctdb->idr, hdr->reqid, struct ctdb_control_state);
        if (state == NULL) {
                DEBUG(DEBUG_ERR,("pnn %u Invalid reqid %u in ctdb_reply_control\n",
                         ctdb->pnn, hdr->reqid));
@@ -744,15 +825,16 @@ void ctdb_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
 
 static int ctdb_control_destructor(struct ctdb_control_state *state)
 {
-       ctdb_reqid_remove(state->ctdb, state->reqid);
+       reqid_remove(state->ctdb->idr, state->reqid);
        return 0;
 }
 
 /*
   handle a timeout of a control
  */
-static void ctdb_control_timeout(struct event_context *ev, struct timed_event *te, 
-                      struct timeval t, void *private_data)
+static void ctdb_control_timeout(struct tevent_context *ev,
+                                struct tevent_timer *te,
+                                struct timeval t, void *private_data)
 {
        struct ctdb_control_state *state = talloc_get_type(private_data, struct ctdb_control_state);
        TALLOC_CTX *tmp_ctx = talloc_new(ev);
@@ -778,7 +860,7 @@ int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
                             ctdb_control_callback_fn_t callback,
                             void *private_data)
 {
-       struct ctdb_req_control *c;
+       struct ctdb_req_control_old *c;
        struct ctdb_control_state *state;
        size_t len;
 
@@ -811,7 +893,7 @@ int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
        state = talloc(private_data?private_data:ctdb, struct ctdb_control_state);
        CTDB_NO_MEMORY(ctdb, state);
 
-       state->reqid = ctdb_reqid_new(ctdb, state);
+       state->reqid = reqid_new(ctdb->idr, state);
        state->callback = callback;
        state->private_data = private_data;
        state->ctdb = ctdb;
@@ -819,9 +901,9 @@ int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
 
        talloc_set_destructor(state, ctdb_control_destructor);
 
-       len = offsetof(struct ctdb_req_control, data) + data.dsize;
+       len = offsetof(struct ctdb_req_control_old, data) + data.dsize;
        c = ctdb_transport_allocate(ctdb, state, CTDB_REQ_CONTROL, len, 
-                                   struct ctdb_req_control);
+                                   struct ctdb_req_control_old);
        CTDB_NO_MEMORY(ctdb, c);
        talloc_set_name_const(c, "ctdb_req_control packet");
 
@@ -844,9 +926,9 @@ int ctdb_daemon_send_control(struct ctdb_context *ctdb, uint32_t destnode,
        }
 
        if (ctdb->tunable.control_timeout) {
-               event_add_timed(ctdb->ev, state, 
-                               timeval_current_ofs(ctdb->tunable.control_timeout, 0), 
-                               ctdb_control_timeout, state);
+               tevent_add_timer(ctdb->ev, state,
+                                timeval_current_ofs(ctdb->tunable.control_timeout, 0),
+                                ctdb_control_timeout, state);
        }
 
        talloc_free(c);