struct ctdb_registered_call *fn;
struct ctdb_context *ctdb = ctdb_db->ctdb;
- c = talloc(ctdb, struct ctdb_call_info);
+ c = talloc_zero(mem_ctx, struct ctdb_call_info);
CTDB_NO_MEMORY(ctdb, c);
c->key = call->key;
c->record_data.dptr = talloc_memdup(c, data->dptr, data->dsize);
c->record_data.dsize = data->dsize;
CTDB_NO_MEMORY(ctdb, c->record_data.dptr);
- c->new_data = NULL;
- c->reply_data = NULL;
- c->status = 0;
c->header = header;
for (fn=ctdb_db->calls;fn;fn=fn->next) {
int ctdb_socket_connect(struct ctdb_context *ctdb)
{
struct sockaddr_un addr;
+ int ret;
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
}
if (connect(ctdb->daemon.sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
+ DEBUG(DEBUG_ERR,
+ (__location__
+ "Failed to connect client socket to daemon (%s)\n",
+ strerror(errno)));
+ close(ctdb->daemon.sd);
+ ctdb->daemon.sd = -1;
+ return -1;
+ }
+
+ ret = set_blocking(ctdb->daemon.sd, false);
+ if (ret != 0) {
+ DEBUG(DEBUG_ERR,
+ (__location__
+ " failed to set socket non-blocking (%s)\n",
+ strerror(errno)));
close(ctdb->daemon.sd);
ctdb->daemon.sd = -1;
- DEBUG(DEBUG_ERR,(__location__ " Failed to connect client socket to daemon. Errno:%s(%d)\n", strerror(errno), errno));
return -1;
}
- set_blocking(ctdb->daemon.sd, false);
set_close_on_exec(ctdb->daemon.sd);
ctdb->daemon.queue = ctdb_queue_setup(ctdb, ctdb, ctdb->daemon.sd,
return 0;
}
-/*
- * check server ids
- */
-int ctdb_client_check_message_handlers(struct ctdb_context *ctdb, uint64_t *ids, uint32_t num,
- uint8_t *result)
-{
- TDB_DATA indata, outdata;
- int res;
- int32_t status;
- int i;
-
- indata.dptr = (uint8_t *)ids;
- indata.dsize = num * sizeof(*ids);
-
- res = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_CHECK_SRVIDS, 0,
- indata, ctdb, &outdata, &status, NULL, NULL);
- if (res != 0 || status != 0) {
- DEBUG(DEBUG_ERR, (__location__ " failed to check srvids\n"));
- return -1;
- }
-
- if (outdata.dsize != num*sizeof(uint8_t)) {
- DEBUG(DEBUG_ERR, (__location__ " expected %lu bytes, received %zi bytes\n",
- (long unsigned int)num*sizeof(uint8_t),
- outdata.dsize));
- talloc_free(outdata.dptr);
- return -1;
- }
-
- for (i=0; i<num; i++) {
- result[i] = outdata.dptr[i];
- }
-
- talloc_free(outdata.dptr);
- return 0;
-}
-
/*
send a message - from client context
*/
*/
int ctdb_record_store(struct ctdb_record_handle *h, TDB_DATA data)
{
- if (h->ctdb_db->persistent) {
- DEBUG(DEBUG_ERR, (__location__ " ctdb_record_store prohibited for persistent dbs\n"));
+ if (! ctdb_db_volatile(h->ctdb_db)) {
+ DEBUG(DEBUG_ERR,
+ ("ctdb_record_store prohibited for non-volatile dbs\n"));
return -1;
}
int ret;
int32_t res;
TDB_DATA data, outdata;
+ uint8_t buf[sizeof(uint64_t)] = { 0 };
- data.dptr = (uint8_t *)&dbid;
- data.dsize = sizeof(uint64_t); /* This is just wrong */
+ *(uint32_t *)buf = dbid;
+ data.dptr = buf;
+ data.dsize = sizeof(uint64_t);
ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_GET_DB_SEQNUM,
0, data, ctdb, &outdata, &res, &timeout, NULL);
/*
create a database
*/
-int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode,
- TALLOC_CTX *mem_ctx, const char *name, bool persistent)
+int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout,
+ uint32_t destnode, TALLOC_CTX *mem_ctx,
+ const char *name, uint8_t db_flags, uint32_t *db_id)
{
int ret;
int32_t res;
TDB_DATA data;
- uint64_t tdb_flags = 0;
+ uint32_t opcode;
data.dptr = discard_const(name);
data.dsize = strlen(name)+1;
- /* Make sure that volatile databases use jenkins hash */
- if (!persistent) {
- tdb_flags = TDB_INCOMPATIBLE_HASH;
- }
-
-#ifdef TDB_MUTEX_LOCKING
- if (!persistent && ctdb->tunable.mutex_enabled == 1) {
- tdb_flags |= (TDB_MUTEX_LOCKING | TDB_CLEAR_IF_FIRST);
+ if (db_flags & CTDB_DB_FLAGS_PERSISTENT) {
+ opcode = CTDB_CONTROL_DB_ATTACH_PERSISTENT;
+ } else if (db_flags & CTDB_DB_FLAGS_REPLICATED) {
+ opcode = CTDB_CONTROL_DB_ATTACH_REPLICATED;
+ } else {
+ opcode = CTDB_CONTROL_DB_ATTACH;
}
-#endif
- ret = ctdb_control(ctdb, destnode, tdb_flags,
- persistent?CTDB_CONTROL_DB_ATTACH_PERSISTENT:CTDB_CONTROL_DB_ATTACH,
- 0, data,
+ ret = ctdb_control(ctdb, destnode, 0, opcode, 0, data,
mem_ctx, &data, &res, &timeout, NULL);
if (ret != 0 || res != 0) {
return -1;
}
+ if (data.dsize != sizeof(uint32_t)) {
+ TALLOC_FREE(data.dptr);
+ return -1;
+ }
+ if (db_id != NULL) {
+ *db_id = *(uint32_t *)data.dptr;
+ }
+ talloc_free(data.dptr);
+
return 0;
}
return 0;
}
+/*
+ * Get db open flags
+ */
+int ctdb_ctrl_db_open_flags(struct ctdb_context *ctdb, uint32_t db_id,
+ int *tdb_flags)
+{
+ TDB_DATA indata, outdata;
+ int ret;
+ int32_t res;
+
+ indata.dptr = (uint8_t *)&db_id;
+ indata.dsize = sizeof(db_id);
+
+ ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0,
+ CTDB_CONTROL_DB_OPEN_FLAGS, 0, indata,
+ ctdb, &outdata, &res, NULL, NULL);
+ if (ret != 0 || res != 0) {
+ D_ERR("ctdb control for db open flags failed\n");
+ return -1;
+ }
+
+ if (outdata.dsize != sizeof(int32_t)) {
+ D_ERR(__location__ " expected %zi bytes, received %zi bytes\n",
+ sizeof(int32_t), outdata.dsize);
+ talloc_free(outdata.dptr);
+ return -1;
+ }
+
+ *tdb_flags = *(int32_t *)outdata.dptr;
+ talloc_free(outdata.dptr);
+ return 0;
+}
+
/*
attach to a specific database - client call
*/
struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
struct timeval timeout,
const char *name,
- bool persistent,
- uint32_t tdb_flags)
+ uint8_t db_flags)
{
struct ctdb_db_context *ctdb_db;
- TDB_DATA data;
int ret;
- int32_t res;
-#ifdef TDB_MUTEX_LOCKING
- uint32_t mutex_enabled = 0;
-#endif
+ int tdb_flags;
ctdb_db = ctdb_db_handle(ctdb, name);
if (ctdb_db) {
ctdb_db->db_name = talloc_strdup(ctdb_db, name);
CTDB_NO_MEMORY_NULL(ctdb, ctdb_db->db_name);
- data.dptr = discard_const(name);
- data.dsize = strlen(name)+1;
-
- /* CTDB has switched to using jenkins hash for volatile databases.
- * Even if tdb_flags do not explicitly mention TDB_INCOMPATIBLE_HASH,
- * always set it.
- */
- if (!persistent) {
- tdb_flags |= TDB_INCOMPATIBLE_HASH;
- }
-
-#ifdef TDB_MUTEX_LOCKING
- if (!persistent) {
- ret = ctdb_ctrl_get_tunable(ctdb, timeval_current_ofs(3,0),
- CTDB_CURRENT_NODE,
- "TDBMutexEnabled",
- &mutex_enabled);
- if (ret != 0) {
- DEBUG(DEBUG_WARNING, ("Assuming no mutex support.\n"));
- }
-
- if (mutex_enabled == 1) {
- tdb_flags |= (TDB_MUTEX_LOCKING | TDB_CLEAR_IF_FIRST);
- }
- }
-#endif
-
/* tell ctdb daemon to attach */
- ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, tdb_flags,
- persistent?CTDB_CONTROL_DB_ATTACH_PERSISTENT:CTDB_CONTROL_DB_ATTACH,
- 0, data, ctdb_db, &data, &res, NULL, NULL);
- if (ret != 0 || res != 0 || data.dsize != sizeof(uint32_t)) {
+ ret = ctdb_ctrl_createdb(ctdb, timeout, CTDB_CURRENT_NODE,
+ ctdb_db, name, db_flags, &ctdb_db->db_id);
+ if (ret != 0) {
DEBUG(DEBUG_ERR,("Failed to attach to database '%s'\n", name));
talloc_free(ctdb_db);
return NULL;
}
-
- ctdb_db->db_id = *(uint32_t *)data.dptr;
- talloc_free(data.dptr);
ret = ctdb_ctrl_getdbpath(ctdb, timeout, CTDB_CURRENT_NODE, ctdb_db->db_id, ctdb_db, &ctdb_db->db_path);
if (ret != 0) {
return NULL;
}
- if (persistent) {
- tdb_flags = TDB_DEFAULT;
- } else {
- tdb_flags = TDB_NOSYNC;
-#ifdef TDB_MUTEX_LOCKING
- if (mutex_enabled) {
- tdb_flags |= (TDB_MUTEX_LOCKING | TDB_CLEAR_IF_FIRST);
- }
-#endif
- }
- if (ctdb->valgrinding) {
- tdb_flags |= TDB_NOMMAP;
+ ret = ctdb_ctrl_db_open_flags(ctdb, ctdb_db->db_id, &tdb_flags);
+ if (ret != 0) {
+ D_ERR("Failed to get tdb_flags for database '%s'\n", name);
+ talloc_free(ctdb_db);
+ return NULL;
}
- tdb_flags |= TDB_DISALLOW_NESTING;
ctdb_db->ltdb = tdb_wrap_open(ctdb_db, ctdb_db->db_path, 0, tdb_flags,
O_RDWR, 0);
return NULL;
}
- ctdb_db->persistent = persistent;
+ ctdb_db->db_flags = db_flags;
DLIST_ADD(ctdb->db_list, ctdb_db);
return 0;
}
-
-/*
- async freeze send control
- */
-struct ctdb_client_control_state *
-ctdb_ctrl_freeze_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, uint32_t priority)
-{
- return ctdb_control_send(ctdb, destnode, priority,
- CTDB_CONTROL_FREEZE, 0, tdb_null,
- mem_ctx, &timeout, NULL);
-}
-
-/*
- async freeze recv control
-*/
-int ctdb_ctrl_freeze_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state)
+/* Freeze all databases */
+int ctdb_ctrl_freeze(struct ctdb_context *ctdb, struct timeval timeout,
+ uint32_t destnode)
{
int ret;
int32_t res;
- ret = ctdb_control_recv(ctdb, state, mem_ctx, NULL, &res, NULL);
- if ( (ret != 0) || (res != 0) ){
- DEBUG(DEBUG_ERR,(__location__ " ctdb_ctrl_freeze_recv failed\n"));
+ ret = ctdb_control(ctdb, destnode, 0,
+ CTDB_CONTROL_FREEZE, 0, tdb_null,
+ NULL, NULL, &res, &timeout, NULL);
+ if (ret != 0 || res != 0) {
+ DEBUG(DEBUG_ERR, ("ctdb_ctrl_freeze_priority failed\n"));
return -1;
}
return 0;
}
-/*
- freeze databases of a certain priority
- */
-int ctdb_ctrl_freeze_priority(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t priority)
-{
- TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
- struct ctdb_client_control_state *state;
- int ret;
-
- state = ctdb_ctrl_freeze_send(ctdb, tmp_ctx, timeout, destnode, priority);
- ret = ctdb_ctrl_freeze_recv(ctdb, tmp_ctx, state);
- talloc_free(tmp_ctx);
-
- return ret;
-}
-
-/* Freeze all databases */
-int ctdb_ctrl_freeze(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode)
-{
- int i;
-
- for (i=1; i<=NUM_DB_PRIORITIES; i++) {
- if (ctdb_ctrl_freeze_priority(ctdb, timeout, destnode, i) != 0) {
- return -1;
- }
- }
- return 0;
-}
-
/*
get pnn of a node, or -1
*/
return res;
}
-/*
- get the monitoring mode of a remote node
- */
-int ctdb_ctrl_getmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *monmode)
-{
- int ret;
- int32_t res;
-
- ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_GET_MONMODE, 0, tdb_null,
- NULL, NULL, &res, &timeout, NULL);
- if (ret != 0) {
- DEBUG(DEBUG_ERR,(__location__ " ctdb_control for getmonmode failed\n"));
- return -1;
- }
-
- *monmode = res;
-
- return 0;
-}
-
-
-/*
- set the monitoring mode of a remote node to active
- */
-int ctdb_ctrl_enable_monmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode)
-{
- int ret;
-
-
- ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_ENABLE_MONITOR, 0, tdb_null,
- NULL, NULL,NULL, &timeout, NULL);
- if (ret != 0) {
- DEBUG(DEBUG_ERR,(__location__ " ctdb_control for enable_monitor failed\n"));
- return -1;
- }
-
-
-
- return 0;
-}
-
-/*
- set the monitoring mode of a remote node to disable
- */
-int ctdb_ctrl_disable_monmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode)
-{
- int ret;
-
-
- ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_DISABLE_MONITOR, 0, tdb_null,
- NULL, NULL, NULL, &timeout, NULL);
- if (ret != 0) {
- DEBUG(DEBUG_ERR,(__location__ " ctdb_control for disable_monitor failed\n"));
- return -1;
- }
-
-
-
- return 0;
-}
-
-
/*
sent to a node to make it take over an ip address
}
h->g_lock_db = ctdb_attach(h->ctdb_db->ctdb, timeval_current_ofs(3,0),
- "g_lock.tdb", false, 0);
+ "g_lock.tdb", 0);
if (!h->g_lock_db) {
DEBUG(DEBUG_ERR, (__location__ " unable to attach to g_lock.tdb\n"));
talloc_free(h);
}
if (data.dsize != sizeof(*seqnum)) {
- DEBUG(DEBUG_ERR, (__location__ " Invalid data recived len=%zi\n",
+ DEBUG(DEBUG_ERR, (__location__ " Invalid data received len=%zi\n",
data.dsize));
talloc_free(data.dptr);
return -1;
return 0;
}
-/*
- get the status of running the monitor eventscripts: NULL means never run.
- */
-int ctdb_ctrl_getscriptstatus(struct ctdb_context *ctdb,
- struct timeval timeout, uint32_t destnode,
- TALLOC_CTX *mem_ctx,
- enum ctdb_event type,
- struct ctdb_script_list_old **scripts)
-{
- int ret;
- TDB_DATA outdata, indata;
- int32_t res;
- uint32_t uinttype = type;
-
- indata.dptr = (uint8_t *)&uinttype;
- indata.dsize = sizeof(uinttype);
-
- ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS, 0, indata,
- mem_ctx, &outdata, &res, &timeout, NULL);
- if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,(__location__ " ctdb_control for getscriptstatus failed ret:%d res:%d\n", ret, res));
- return -1;
- }
-
- if (outdata.dsize == 0) {
- *scripts = NULL;
- } else {
- *scripts = (struct ctdb_script_list_old *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
- talloc_free(outdata.dptr);
- }
-
- return 0;
-}
-
/*
tell the main daemon how long it took to lock the reclock file
*/
return 0;
}
-/* enable an eventscript
- */
-int ctdb_ctrl_enablescript(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, const char *script)
-{
- int ret;
- TDB_DATA data;
- int32_t res;
-
- data.dsize = strlen(script) + 1;
- data.dptr = discard_const(script);
-
- ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_ENABLE_SCRIPT, 0, data,
- NULL, NULL, &res, &timeout, NULL);
- if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,(__location__ " ctdb_control for enablescript failed\n"));
- return -1;
- }
-
- return 0;
-}
-
-/* disable an eventscript
- */
-int ctdb_ctrl_disablescript(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, const char *script)
-{
- int ret;
- TDB_DATA data;
- int32_t res;
-
- data.dsize = strlen(script) + 1;
- data.dptr = discard_const(script);
-
- ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_DISABLE_SCRIPT, 0, data,
- NULL, NULL, &res, &timeout, NULL);
- if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,(__location__ " ctdb_control for disablescript failed\n"));
- return -1;
- }
-
- return 0;
-}
-
-
int ctdb_ctrl_set_ban(struct ctdb_context *ctdb, struct timeval timeout,
uint32_t destnode, struct ctdb_ban_state *bantime)
{
return 0;
}
-
-int ctdb_ctrl_set_db_priority(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, struct ctdb_db_priority *db_prio)
-{
- int ret;
- int32_t res;
- TDB_DATA data;
- TALLOC_CTX *tmp_ctx = talloc_new(NULL);
-
- data.dptr = (uint8_t*)db_prio;
- data.dsize = sizeof(*db_prio);
-
- ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_SET_DB_PRIORITY, 0, data,
- tmp_ctx, NULL, &res, &timeout, NULL);
- if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,(__location__ " ctdb_control for set_db_priority failed\n"));
- talloc_free(tmp_ctx);
- return -1;
- }
-
- talloc_free(tmp_ctx);
-
- return 0;
-}
-
-int ctdb_ctrl_get_db_priority(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t db_id, uint32_t *priority)
-{
- int ret;
- int32_t res;
- TDB_DATA data;
- TALLOC_CTX *tmp_ctx = talloc_new(NULL);
-
- data.dptr = (uint8_t*)&db_id;
- data.dsize = sizeof(db_id);
-
- ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_GET_DB_PRIORITY, 0, data,
- tmp_ctx, NULL, &res, &timeout, NULL);
- if (ret != 0 || res < 0) {
- DEBUG(DEBUG_ERR,(__location__ " ctdb_control for get_db_priority failed\n"));
- talloc_free(tmp_ctx);
- return -1;
- }
-
- if (priority) {
- *priority = res;
- }
-
- talloc_free(tmp_ctx);
-
- return 0;
-}
-
int ctdb_ctrl_getstathistory(struct ctdb_context *ctdb,
struct timeval timeout, uint32_t destnode,
TALLOC_CTX *mem_ctx,