along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "includes.h"
-#include "db_wrap.h"
-#include "tdb.h"
-#include "lib/util/dlinklist.h"
+#include "replace.h"
#include "system/network.h"
#include "system/filesys.h"
#include "system/locale.h"
-#include <stdlib.h>
-#include "../include/ctdb_private.h"
+
+#include <talloc.h>
+/* Allow use of deprecated function tevent_loop_allow_nesting() */
+#define TEVENT_DEPRECATED
+#include <tevent.h>
+#include <tdb.h>
+
+#include "lib/tdb_wrap/tdb_wrap.h"
#include "lib/util/dlinklist.h"
+#include "lib/util/time.h"
+#include "lib/util/debug.h"
+#include "lib/util/samba_util.h"
+
+#include "ctdb_logging.h"
+#include "ctdb_private.h"
+#include "ctdb_client.h"
-pid_t ctdbd_pid;
+#include "common/reqid.h"
+#include "common/system.h"
+#include "common/common.h"
/*
allocate a packet for use in client<->daemon communication
hdr->length = length;
hdr->operation = operation;
hdr->ctdb_magic = CTDB_MAGIC;
- hdr->ctdb_version = CTDB_VERSION;
+ hdr->ctdb_version = CTDB_PROTOCOL;
hdr->srcnode = ctdb->pnn;
if (ctdb->vnn_map) {
hdr->generation = ctdb->vnn_map->generation;
*/
static void ctdb_client_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
{
- struct ctdb_reply_call *c = (struct ctdb_reply_call *)hdr;
+ struct ctdb_reply_call_old *c = (struct ctdb_reply_call_old *)hdr;
struct ctdb_client_call_state *state;
- state = ctdb_reqid_find(ctdb, hdr->reqid, struct ctdb_client_call_state);
+ state = reqid_find(ctdb->idr, hdr->reqid, struct ctdb_client_call_state);
if (state == NULL) {
DEBUG(DEBUG_ERR,(__location__ " reqid %u not found\n", hdr->reqid));
return;
}
}
+void ctdb_request_message(struct ctdb_context *ctdb,
+ struct ctdb_req_header *hdr)
+{
+ struct ctdb_req_message_old *c = (struct ctdb_req_message_old *)hdr;
+ TDB_DATA data;
+
+ data.dsize = c->datalen;
+ data.dptr = talloc_memdup(c, &c->data[0], c->datalen);
+ if (data.dptr == NULL) {
+ DEBUG(DEBUG_ERR, (__location__ " Memory allocation failure\n"));
+ return;
+ }
+
+ srvid_dispatch(ctdb->srv, c->srvid, CTDB_SRVID_ALL, data);
+}
+
static void ctdb_client_reply_control(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
/*
goto done;
}
- if (hdr->ctdb_version != CTDB_VERSION) {
+ if (hdr->ctdb_version != CTDB_PROTOCOL) {
ctdb_set_error(ctdb, "Bad CTDB version 0x%x rejected in client\n", hdr->ctdb_version);
goto done;
}
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
- strncpy(addr.sun_path, ctdb->daemon.name, sizeof(addr.sun_path));
+ strncpy(addr.sun_path, ctdb->daemon.name, sizeof(addr.sun_path)-1);
ctdb->daemon.sd = socket(AF_UNIX, SOCK_STREAM, 0);
if (ctdb->daemon.sd == -1) {
}
while (state->state < CTDB_CALL_DONE) {
- event_loop_once(state->ctdb_db->ctdb->ev);
+ tevent_loop_once(state->ctdb_db->ctdb->ev);
}
if (state->state != CTDB_CALL_DONE) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_call_recv failed\n"));
*/
static int ctdb_client_call_destructor(struct ctdb_client_call_state *state)
{
- ctdb_reqid_remove(state->ctdb_db->ctdb, state->reqid);
+ reqid_remove(state->ctdb_db->ctdb->idr, state->reqid);
return 0;
}
TDB_DATA data;
int ret;
size_t len;
- struct ctdb_req_call *c;
+ struct ctdb_req_call_old *c;
/* if the domain socket is not yet open, open it */
if (ctdb->daemon.sd==-1) {
return NULL;
}
- len = offsetof(struct ctdb_req_call, data) + call->key.dsize + call->call_data.dsize;
- c = ctdbd_allocate_pkt(ctdb, state, CTDB_REQ_CALL, len, struct ctdb_req_call);
+ len = offsetof(struct ctdb_req_call_old, data) + call->key.dsize + call->call_data.dsize;
+ c = ctdbd_allocate_pkt(ctdb, state, CTDB_REQ_CALL, len, struct ctdb_req_call_old);
if (c == NULL) {
DEBUG(DEBUG_ERR, (__location__ " failed to allocate packet\n"));
return NULL;
}
- state->reqid = ctdb_reqid_new(ctdb, state);
+ state->reqid = reqid_new(ctdb->idr, state);
state->ctdb_db = ctdb_db;
talloc_set_destructor(state, ctdb_client_call_destructor);
tell the daemon what messaging srvid we will use, and register the message
handler function in the client
*/
-int ctdb_client_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
- ctdb_msg_fn_t handler,
- void *private_data)
+int ctdb_client_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
+ srvid_handler_fn handler,
+ void *private_data)
{
int res;
int32_t status;
- res = ctdb_control(ctdb, CTDB_CURRENT_NODE, srvid, CTDB_CONTROL_REGISTER_SRVID, 0,
+ res = ctdb_control(ctdb, CTDB_CURRENT_NODE, srvid,
+ CTDB_CONTROL_REGISTER_SRVID, 0,
tdb_null, NULL, NULL, &status, NULL, NULL);
if (res != 0 || status != 0) {
- DEBUG(DEBUG_ERR,("Failed to register srvid %llu\n", (unsigned long long)srvid));
+ DEBUG(DEBUG_ERR,
+ ("Failed to register srvid %llu\n",
+ (unsigned long long)srvid));
return -1;
}
/* also need to register the handler with our own ctdb structure */
- return ctdb_register_message_handler(ctdb, ctdb, srvid, handler, private_data);
+ return srvid_register(ctdb->srv, ctdb, srvid, handler, private_data);
}
/*
tell the daemon we no longer want a srvid
*/
-int ctdb_client_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void *private_data)
+int ctdb_client_remove_message_handler(struct ctdb_context *ctdb,
+ uint64_t srvid, void *private_data)
{
int res;
int32_t status;
- res = ctdb_control(ctdb, CTDB_CURRENT_NODE, srvid, CTDB_CONTROL_DEREGISTER_SRVID, 0,
+ res = ctdb_control(ctdb, CTDB_CURRENT_NODE, srvid,
+ CTDB_CONTROL_DEREGISTER_SRVID, 0,
tdb_null, NULL, NULL, &status, NULL, NULL);
if (res != 0 || status != 0) {
- DEBUG(DEBUG_ERR,("Failed to deregister srvid %llu\n", (unsigned long long)srvid));
+ DEBUG(DEBUG_ERR,
+ ("Failed to deregister srvid %llu\n",
+ (unsigned long long)srvid));
return -1;
}
/* also need to register the handler with our own ctdb structure */
- ctdb_deregister_message_handler(ctdb, srvid, private_data);
+ srvid_deregister(ctdb->srv, srvid, private_data);
return 0;
}
int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t pnn,
uint64_t srvid, TDB_DATA data)
{
- struct ctdb_req_message *r;
+ struct ctdb_req_message_old *r;
int len, res;
- len = offsetof(struct ctdb_req_message, data) + data.dsize;
+ len = offsetof(struct ctdb_req_message_old, data) + data.dsize;
r = ctdbd_allocate_pkt(ctdb, ctdb, CTDB_REQ_MESSAGE,
- len, struct ctdb_req_message);
+ len, struct ctdb_req_message_old);
CTDB_NO_MEMORY(ctdb, r);
r->hdr.destnode = pnn;
goto again;
}
+ /* if this is a request for read/write and we have delegations
+ we have to revoke all delegations first
+ */
+ if ((h->header.dmaster == ctdb_db->ctdb->pnn) &&
+ (h->header.flags & CTDB_REC_RO_HAVE_DELEGATIONS)) {
+ ctdb_ltdb_unlock(ctdb_db, key);
+ ret = ctdb_client_force_migration(ctdb_db, key);
+ if (ret != 0) {
+ DEBUG(DEBUG_DEBUG,("ctdb_fetch_readonly_lock: force_migration failed\n"));
+ talloc_free(h);
+ return NULL;
+ }
+ goto again;
+ }
+
DEBUG(DEBUG_DEBUG,("ctdb_fetch_lock: we are dmaster - done\n"));
return h;
}
called when a control completes or timesout to invoke the callback
function the user provided
*/
-static void invoke_control_callback(struct event_context *ev, struct timed_event *te,
- struct timeval t, void *private_data)
+static void invoke_control_callback(struct tevent_context *ev,
+ struct tevent_timer *te,
+ struct timeval t, void *private_data)
{
struct ctdb_client_control_state *state;
TALLOC_CTX *tmp_ctx = talloc_new(NULL);
static void ctdb_client_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;
struct ctdb_client_control_state *state;
- state = ctdb_reqid_find(ctdb, hdr->reqid, struct ctdb_client_control_state);
+ state = reqid_find(ctdb->idr, hdr->reqid, struct ctdb_client_control_state);
if (state == NULL) {
DEBUG(DEBUG_ERR,(__location__ " reqid %u not found\n", hdr->reqid));
return;
and call the callback.
*/
if (state->async.fn) {
- event_add_timed(ctdb->ev, state, timeval_zero(), invoke_control_callback, state);
+ tevent_add_timer(ctdb->ev, state, timeval_zero(),
+ invoke_control_callback, state);
}
}
*/
static int ctdb_client_control_destructor(struct ctdb_client_control_state *state)
{
- ctdb_reqid_remove(state->ctdb, state->reqid);
+ reqid_remove(state->ctdb->idr, state->reqid);
return 0;
}
/* time out handler for ctdb_control */
-static void control_timeout_func(struct event_context *ev, struct timed_event *te,
- struct timeval t, void *private_data)
+static void control_timeout_func(struct tevent_context *ev,
+ struct tevent_timer *te,
+ struct timeval t, void *private_data)
{
struct ctdb_client_control_state *state = talloc_get_type(private_data, struct ctdb_client_control_state);
and call the callback.
*/
if (state->async.fn) {
- event_add_timed(state->ctdb->ev, state, timeval_zero(), invoke_control_callback, state);
+ tevent_add_timer(state->ctdb->ev, state, timeval_zero(),
+ invoke_control_callback, state);
}
}
{
struct ctdb_client_control_state *state;
size_t len;
- struct ctdb_req_control *c;
+ struct ctdb_req_control_old *c;
int ret;
if (errormsg) {
CTDB_NO_MEMORY_NULL(ctdb, state);
state->ctdb = ctdb;
- state->reqid = ctdb_reqid_new(ctdb, state);
+ state->reqid = reqid_new(ctdb->idr, state);
state->state = CTDB_CONTROL_WAIT;
state->errormsg = NULL;
talloc_set_destructor(state, ctdb_client_control_destructor);
- len = offsetof(struct ctdb_req_control, data) + data.dsize;
+ len = offsetof(struct ctdb_req_control_old, data) + data.dsize;
c = ctdbd_allocate_pkt(ctdb, state, CTDB_REQ_CONTROL,
- len, struct ctdb_req_control);
+ len, struct ctdb_req_control_old);
state->c = c;
CTDB_NO_MEMORY_NULL(ctdb, c);
c->hdr.reqid = state->reqid;
/* timeout */
if (timeout && !timeval_is_zero(timeout)) {
- event_add_timed(ctdb->ev, state, *timeout, control_timeout_func, state);
+ tevent_add_timer(ctdb->ev, state, *timeout,
+ control_timeout_func, state);
}
ret = ctdb_client_queue_pkt(ctdb, &(c->hdr));
completes.
*/
while (state->state == CTDB_CONTROL_WAIT) {
- event_loop_once(ctdb->ev);
+ tevent_loop_once(ctdb->ev);
}
if (state->state != CTDB_CONTROL_DONE) {
state->async.fn(state);
}
talloc_free(tmp_ctx);
- return -1;
+ return (status == 0 ? -1 : state->status);
}
if (outdata) {
* get db statistics
*/
int ctdb_ctrl_dbstatistics(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
- TALLOC_CTX *mem_ctx, struct ctdb_db_statistics **dbstat)
+ TALLOC_CTX *mem_ctx, struct ctdb_db_statistics_old **dbstat)
{
int ret;
TDB_DATA indata, outdata;
int32_t res;
- struct ctdb_db_statistics *wire, *s;
+ struct ctdb_db_statistics_old *wire, *s;
char *ptr;
int i;
return -1;
}
- if (outdata.dsize < offsetof(struct ctdb_db_statistics, hot_keys_wire)) {
+ if (outdata.dsize < offsetof(struct ctdb_db_statistics_old, hot_keys_wire)) {
DEBUG(DEBUG_ERR,(__location__ " Wrong dbstatistics size %zi - expected >= %lu\n",
outdata.dsize,
(long unsigned int)sizeof(struct ctdb_statistics)));
return -1;
}
- s = talloc_zero(mem_ctx, struct ctdb_db_statistics);
+ s = talloc_zero(mem_ctx, struct ctdb_db_statistics_old);
if (s == NULL) {
talloc_free(outdata.dptr);
CTDB_NO_MEMORY(ctdb, s);
}
- wire = (struct ctdb_db_statistics *)outdata.dptr;
- *s = *wire;
+ wire = (struct ctdb_db_statistics_old *)outdata.dptr;
+ memcpy(s, wire, offsetof(struct ctdb_db_statistics_old, hot_keys_wire));
ptr = &wire->hot_keys_wire[0];
for (i=0; i<wire->num_hot_keys; i++) {
s->hot_keys[i].key.dptr = talloc_size(mem_ctx, s->hot_keys[i].key.dsize);
get a list of databases off a remote node
*/
int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode,
- TALLOC_CTX *mem_ctx, struct ctdb_dbid_map **dbmap)
+ TALLOC_CTX *mem_ctx, struct ctdb_dbid_map_old **dbmap)
{
int ret;
TDB_DATA outdata;
return -1;
}
- *dbmap = (struct ctdb_dbid_map *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
+ *dbmap = (struct ctdb_dbid_map_old *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
talloc_free(outdata.dptr);
return 0;
*/
int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb,
struct timeval timeout, uint32_t destnode,
- TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap)
+ TALLOC_CTX *mem_ctx, struct ctdb_node_map_old **nodemap)
{
int ret;
TDB_DATA outdata;
int32_t res;
- ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_GET_NODEMAP, 0, tdb_null,
+ ret = ctdb_control(ctdb, destnode, 0,
+ CTDB_CONTROL_GET_NODEMAP, 0, tdb_null,
mem_ctx, &outdata, &res, &timeout, NULL);
- if (ret == 0 && res == -1 && outdata.dsize == 0) {
- DEBUG(DEBUG_ERR,(__location__ " ctdb_control for getnodes failed, falling back to ipv4-only control\n"));
- return ctdb_ctrl_getnodemapv4(ctdb, timeout, destnode, mem_ctx, nodemap);
- }
if (ret != 0 || res != 0 || outdata.dsize == 0) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_control for getnodes failed ret:%d res:%d\n", ret, res));
return -1;
}
- *nodemap = (struct ctdb_node_map *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
+ *nodemap = (struct ctdb_node_map_old *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
talloc_free(outdata.dptr);
-
return 0;
}
/*
- old style ipv4-only get a list of nodes (vnn and flags ) from a remote node
+ load nodes file on a remote node and return as a node map
*/
-int ctdb_ctrl_getnodemapv4(struct ctdb_context *ctdb,
- struct timeval timeout, uint32_t destnode,
- TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap)
+int ctdb_ctrl_getnodesfile(struct ctdb_context *ctdb,
+ struct timeval timeout, uint32_t destnode,
+ TALLOC_CTX *mem_ctx, struct ctdb_node_map_old **nodemap)
{
- int ret, i, len;
+ int ret;
TDB_DATA outdata;
- struct ctdb_node_mapv4 *nodemapv4;
int32_t res;
- ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_GET_NODEMAPv4, 0, tdb_null,
+ ret = ctdb_control(ctdb, destnode, 0,
+ CTDB_CONTROL_GET_NODES_FILE, 0, tdb_null,
mem_ctx, &outdata, &res, &timeout, NULL);
if (ret != 0 || res != 0 || outdata.dsize == 0) {
- DEBUG(DEBUG_ERR,(__location__ " ctdb_control for getnodesv4 failed ret:%d res:%d\n", ret, res));
+ DEBUG(DEBUG_ERR,(__location__ " ctdb_control for getnodes failed ret:%d res:%d\n", ret, res));
return -1;
}
- nodemapv4 = (struct ctdb_node_mapv4 *)outdata.dptr;
-
- len = offsetof(struct ctdb_node_map, nodes) + nodemapv4->num*sizeof(struct ctdb_node_and_flags);
- (*nodemap) = talloc_zero_size(mem_ctx, len);
- CTDB_NO_MEMORY(ctdb, (*nodemap));
-
- (*nodemap)->num = nodemapv4->num;
- for (i=0; i<nodemapv4->num; i++) {
- (*nodemap)->nodes[i].pnn = nodemapv4->nodes[i].pnn;
- (*nodemap)->nodes[i].flags = nodemapv4->nodes[i].flags;
- (*nodemap)->nodes[i].addr.ip = nodemapv4->nodes[i].sin;
- (*nodemap)->nodes[i].addr.sa.sa_family = AF_INET;
- }
-
+ *nodemap = (struct ctdb_node_map_old *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
talloc_free(outdata.dptr);
-
+
return 0;
}
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);
+ }
+#endif
+
ret = ctdb_control(ctdb, destnode, tdb_flags,
persistent?CTDB_CONTROL_DB_ATTACH_PERSISTENT:CTDB_CONTROL_DB_ATTACH,
0, data,
TALLOC_CTX *mem_ctx,
uint32_t *num_nodes)
{
- struct ctdb_node_map *map=NULL;
+ struct ctdb_node_map_old *map=NULL;
int ret, i;
uint32_t *nodes;
TDB_DATA data;
int ret;
int32_t res;
+#ifdef TDB_MUTEX_LOCKING
+ uint32_t mutex_enabled = 0;
+#endif
ctdb_db = ctdb_db_handle(ctdb, name);
if (ctdb_db) {
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,
return NULL;
}
- tdb_flags = persistent?TDB_DEFAULT:TDB_NOSYNC;
+ 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;
}
tdb_flags |= TDB_DISALLOW_NESTING;
- ctdb_db->ltdb = tdb_wrap_open(ctdb, ctdb_db->db_path, 0, tdb_flags, O_RDWR, 0);
+ ctdb_db->ltdb = tdb_wrap_open(ctdb_db, ctdb_db->db_path, 0, tdb_flags,
+ O_RDWR, 0);
if (ctdb_db->ltdb == NULL) {
ctdb_set_error(ctdb, "Failed to open tdb '%s'\n", ctdb_db->db_path);
talloc_free(ctdb_db);
return ctdb_db;
}
-
/*
- setup a call for a database
+ * detach from a specific database - client call
*/
-int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id)
+int ctdb_detach(struct ctdb_context *ctdb, uint32_t db_id)
{
- struct ctdb_registered_call *call;
-
-#if 0
- TDB_DATA data;
- int32_t status;
- struct ctdb_control_set_call c;
int ret;
+ int32_t status;
+ TDB_DATA data;
- /* this is no longer valid with the separate daemon architecture */
- c.db_id = ctdb_db->db_id;
- c.fn = fn;
- c.id = id;
-
- data.dptr = (uint8_t *)&c;
- data.dsize = sizeof(c);
+ data.dsize = sizeof(db_id);
+ data.dptr = (uint8_t *)&db_id;
- ret = ctdb_control(ctdb_db->ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_SET_CALL, 0,
- data, NULL, NULL, &status, NULL, NULL);
+ ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_DB_DETACH,
+ 0, data, NULL, NULL, &status, NULL, NULL);
if (ret != 0 || status != 0) {
- DEBUG(DEBUG_ERR,("ctdb_set_call failed for call %u\n", id));
return -1;
}
-#endif
+ return 0;
+}
+
+/*
+ setup a call for a database
+ */
+int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id)
+{
+ struct ctdb_registered_call *call;
- /* also register locally */
+ /* register locally */
call = talloc(ctdb_db, struct ctdb_registered_call);
call->fn = fn;
call->id = id;
- DLIST_ADD(ctdb_db->calls, call);
+ DLIST_ADD(ctdb_db->calls, call);
return 0;
}
/*
called on each key during a ctdb_traverse
*/
-static void traverse_handler(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data, void *p)
+static void traverse_handler(uint64_t srvid, TDB_DATA data, void *p)
{
struct traverse_state *state = (struct traverse_state *)p;
- struct ctdb_rec_data *d = (struct ctdb_rec_data *)data.dptr;
+ struct ctdb_rec_data_old *d = (struct ctdb_rec_data_old *)data.dptr;
TDB_DATA key;
- if (data.dsize < sizeof(uint32_t) ||
- d->length != data.dsize) {
- DEBUG(DEBUG_ERR,("Bad data size %u in traverse_handler\n", (unsigned)data.dsize));
+ if (data.dsize < sizeof(uint32_t) || d->length != data.dsize) {
+ DEBUG(DEBUG_ERR, ("Bad data size %u in traverse_handler\n",
+ (unsigned)data.dsize));
state->done = true;
return;
}
return;
}
- if (state->fn(ctdb, key, data, state->private_data) != 0) {
+ if (state->fn(key, data, state->private_data) != 0) {
state->done = true;
}
}
while (!state.done) {
- event_loop_once(ctdb_db->ctdb->ev);
+ tevent_loop_once(ctdb_db->ctdb->ev);
}
ret = ctdb_client_remove_message_handler(ctdb_db->ctdb, srvid, &state);
/*
called on each key during a catdb
*/
-int ctdb_dumpdb_record(struct ctdb_context *ctdb, TDB_DATA key, TDB_DATA data, void *p)
+int ctdb_dumpdb_record(TDB_DATA key, TDB_DATA data, void *p)
{
int i;
struct ctdb_dump_db_context *c = (struct ctdb_dump_db_context *)p;
fprintf(f, "dmaster: %u\n", h->dmaster);
fprintf(f, "rsn: %llu\n", (unsigned long long)h->rsn);
- if (c->printlmaster && ctdb->vnn_map != NULL) {
- fprintf(f, "lmaster: %u\n", ctdb_lmaster(ctdb, &key));
+ if (c->printlmaster && c->ctdb->vnn_map != NULL) {
+ fprintf(f, "lmaster: %u\n", ctdb_lmaster(c->ctdb, &key));
}
if (c->printhash) {
-/*
+/*
sent to a node to make it take over an ip address
*/
-int ctdb_ctrl_takeover_ip(struct ctdb_context *ctdb, struct timeval timeout,
+int ctdb_ctrl_takeover_ip(struct ctdb_context *ctdb, struct timeval timeout,
uint32_t destnode, struct ctdb_public_ip *ip)
{
TDB_DATA data;
- struct ctdb_public_ipv4 ipv4;
int ret;
int32_t res;
- if (ip->addr.sa.sa_family == AF_INET) {
- ipv4.pnn = ip->pnn;
- ipv4.sin = ip->addr.ip;
-
- data.dsize = sizeof(ipv4);
- data.dptr = (uint8_t *)&ipv4;
-
- ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_TAKEOVER_IPv4, 0, data, NULL,
- NULL, &res, &timeout, NULL);
- } else {
- data.dsize = sizeof(*ip);
- data.dptr = (uint8_t *)ip;
-
- ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_TAKEOVER_IP, 0, data, NULL,
- NULL, &res, &timeout, NULL);
- }
+ data.dsize = sizeof(*ip);
+ data.dptr = (uint8_t *)ip;
+ ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_TAKEOVER_IP, 0,
+ data, NULL, NULL, &res, &timeout, NULL);
if (ret != 0 || res != 0) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_control for takeover_ip failed\n"));
return -1;
}
- return 0;
+ return 0;
}
-/*
+/*
sent to a node to make it release an ip address
*/
-int ctdb_ctrl_release_ip(struct ctdb_context *ctdb, struct timeval timeout,
+int ctdb_ctrl_release_ip(struct ctdb_context *ctdb, struct timeval timeout,
uint32_t destnode, struct ctdb_public_ip *ip)
{
TDB_DATA data;
- struct ctdb_public_ipv4 ipv4;
int ret;
int32_t res;
- if (ip->addr.sa.sa_family == AF_INET) {
- ipv4.pnn = ip->pnn;
- ipv4.sin = ip->addr.ip;
-
- data.dsize = sizeof(ipv4);
- data.dptr = (uint8_t *)&ipv4;
-
- ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_RELEASE_IPv4, 0, data, NULL,
- NULL, &res, &timeout, NULL);
- } else {
- data.dsize = sizeof(*ip);
- data.dptr = (uint8_t *)ip;
-
- ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_RELEASE_IP, 0, data, NULL,
- NULL, &res, &timeout, NULL);
- }
+ data.dsize = sizeof(*ip);
+ data.dptr = (uint8_t *)ip;
+ ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_RELEASE_IP, 0,
+ data, NULL, NULL, &res, &timeout, NULL);
if (ret != 0 || res != 0) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_control for release_ip failed\n"));
return -1;
}
- return 0;
+ return 0;
}
ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_SET_TUNABLE, 0, data, NULL,
NULL, &res, &timeout, NULL);
talloc_free(data.dptr);
- if (ret != 0 || res != 0) {
+ if ((ret != 0) || (res == -1)) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_control for set_tunable failed\n"));
return -1;
}
- return 0;
+ return res;
}
/*
struct timeval timeout, uint32_t destnode,
TALLOC_CTX *mem_ctx,
uint32_t flags,
- struct ctdb_all_public_ips **ips)
+ struct ctdb_public_ip_list_old **ips)
{
int ret;
TDB_DATA outdata;
int32_t res;
- ret = ctdb_control(ctdb, destnode, 0,
+ ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_GET_PUBLIC_IPS, flags, tdb_null,
mem_ctx, &outdata, &res, &timeout, NULL);
- if (ret == 0 && res == -1) {
- DEBUG(DEBUG_ERR,(__location__ " ctdb_control to get public ips failed, falling back to ipv4-only version\n"));
- return ctdb_ctrl_get_public_ipsv4(ctdb, timeout, destnode, mem_ctx, ips);
- }
if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,(__location__ " ctdb_control for getpublicips failed ret:%d res:%d\n", ret, res));
+ DEBUG(DEBUG_ERR,(__location__
+ " ctdb_control for getpublicips failed ret:%d res:%d\n",
+ ret, res));
return -1;
}
- *ips = (struct ctdb_all_public_ips *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
+ *ips = (struct ctdb_public_ip_list_old *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
talloc_free(outdata.dptr);
-
+
return 0;
}
int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb,
struct timeval timeout, uint32_t destnode,
TALLOC_CTX *mem_ctx,
- struct ctdb_all_public_ips **ips)
+ struct ctdb_public_ip_list_old **ips)
{
return ctdb_ctrl_get_public_ips_flags(ctdb, timeout,
destnode, mem_ctx,
0, ips);
}
-int ctdb_ctrl_get_public_ipsv4(struct ctdb_context *ctdb,
- struct timeval timeout, uint32_t destnode,
- TALLOC_CTX *mem_ctx, struct ctdb_all_public_ips **ips)
-{
- int ret, i, len;
- TDB_DATA outdata;
- int32_t res;
- struct ctdb_all_public_ipsv4 *ipsv4;
-
- ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_GET_PUBLIC_IPSv4, 0, tdb_null,
- mem_ctx, &outdata, &res, &timeout, NULL);
- if (ret != 0 || res != 0) {
- DEBUG(DEBUG_ERR,(__location__ " ctdb_control for getpublicips failed\n"));
- return -1;
- }
-
- ipsv4 = (struct ctdb_all_public_ipsv4 *)outdata.dptr;
- len = offsetof(struct ctdb_all_public_ips, ips) +
- ipsv4->num*sizeof(struct ctdb_public_ip);
- *ips = talloc_zero_size(mem_ctx, len);
- CTDB_NO_MEMORY(ctdb, *ips);
- (*ips)->num = ipsv4->num;
- for (i=0; i<ipsv4->num; i++) {
- (*ips)->ips[i].pnn = ipsv4->ips[i].pnn;
- (*ips)->ips[i].addr.ip = ipsv4->ips[i].sin;
- }
-
- talloc_free(outdata.dptr);
-
- return 0;
-}
-
int ctdb_ctrl_get_public_ip_info(struct ctdb_context *ctdb,
struct timeval timeout, uint32_t destnode,
TALLOC_CTX *mem_ctx,
{
int ret;
TDB_DATA data;
- struct ctdb_node_map *nodemap=NULL;
+ struct ctdb_node_map_old *nodemap=NULL;
struct ctdb_node_flag_change c;
TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
uint32_t recmaster;
int ctdb_ctrl_killtcp(struct ctdb_context *ctdb,
struct timeval timeout,
uint32_t destnode,
- struct ctdb_control_killtcp *killtcp)
+ struct ctdb_tcp_connection *killtcp)
{
TDB_DATA data;
int32_t res;
int ret;
- data.dsize = sizeof(struct ctdb_control_killtcp);
+ data.dsize = sizeof(struct ctdb_tcp_connection);
data.dptr = (unsigned char *)killtcp;
ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_KILL_TCP, 0, data, NULL,
/*
register a server id
*/
-int ctdb_ctrl_register_server_id(struct ctdb_context *ctdb,
- struct timeval timeout,
- struct ctdb_server_id *id)
+int ctdb_ctrl_register_server_id(struct ctdb_context *ctdb,
+ struct timeval timeout,
+ struct ctdb_client_id *id)
{
TDB_DATA data;
int32_t res;
int ret;
- data.dsize = sizeof(struct ctdb_server_id);
+ data.dsize = sizeof(struct ctdb_client_id);
data.dptr = (unsigned char *)id;
ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0,
/*
unregister a server id
*/
-int ctdb_ctrl_unregister_server_id(struct ctdb_context *ctdb,
- struct timeval timeout,
- struct ctdb_server_id *id)
+int ctdb_ctrl_unregister_server_id(struct ctdb_context *ctdb,
+ struct timeval timeout,
+ struct ctdb_client_id *id)
{
TDB_DATA data;
int32_t res;
int ret;
- data.dsize = sizeof(struct ctdb_server_id);
+ data.dsize = sizeof(struct ctdb_client_id);
data.dptr = (unsigned char *)id;
ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0,
if a server id does exist, return *status == 1, otherwise *status == 0
*/
-int ctdb_ctrl_check_server_id(struct ctdb_context *ctdb,
- struct timeval timeout,
- uint32_t destnode,
- struct ctdb_server_id *id,
- uint32_t *status)
+int ctdb_ctrl_check_server_id(struct ctdb_context *ctdb,
+ struct timeval timeout, uint32_t destnode,
+ struct ctdb_client_id *id, uint32_t *status)
{
TDB_DATA data;
int32_t res;
int ret;
- data.dsize = sizeof(struct ctdb_server_id);
+ data.dsize = sizeof(struct ctdb_client_id);
data.dptr = (unsigned char *)id;
ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_CHECK_SERVER_ID,
get the list of server ids that are registered on a node
*/
int ctdb_ctrl_get_server_id_list(struct ctdb_context *ctdb,
- TALLOC_CTX *mem_ctx,
- struct timeval timeout, uint32_t destnode,
- struct ctdb_server_id_list **svid_list)
+ TALLOC_CTX *mem_ctx,
+ struct timeval timeout, uint32_t destnode,
+ struct ctdb_client_id_list_old **svid_list)
{
int ret;
TDB_DATA outdata;
return -1;
}
- *svid_list = (struct ctdb_server_id_list *)talloc_steal(mem_ctx, outdata.dptr);
-
+ *svid_list = (struct ctdb_client_id_list_old *)talloc_steal(mem_ctx, outdata.dptr);
+
return 0;
}
NOTE: In current code the daemon does not fork. This is for testing purposes only
and to simplify the code.
*/
-struct ctdb_context *ctdb_init(struct event_context *ev)
+struct ctdb_context *ctdb_init(struct tevent_context *ev)
{
int ret;
struct ctdb_context *ctdb;
return NULL;
}
ctdb->ev = ev;
- ctdb->idr = idr_init(ctdb);
/* Wrap early to exercise code. */
- ctdb->lastid = INT_MAX-200;
- CTDB_NO_MEMORY_NULL(ctdb, ctdb->idr);
+ ret = reqid_init(ctdb, INT_MAX-200, &ctdb->idr);
+ if (ret != 0) {
+ DEBUG(DEBUG_ERR, ("reqid_init failed (%s)\n", strerror(ret)));
+ talloc_free(ctdb);
+ return NULL;
+ }
+
+ ret = srvid_init(ctdb, &ctdb->srv);
+ if (ret != 0) {
+ DEBUG(DEBUG_ERR, ("srvid_init failed (%s)\n", strerror(ret)));
+ talloc_free(ctdb);
+ return NULL;
+ }
- ret = ctdb_set_socketname(ctdb, CTDB_PATH);
+ ret = ctdb_set_socketname(ctdb, CTDB_SOCKET);
if (ret != 0) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_set_socketname failed.\n"));
talloc_free(ctdb);
int32_t res = -1;
uint32_t destnode = state->c->hdr.destnode;
+ outdata.dsize = 0;
+ outdata.dptr = NULL;
+
/* one more node has responded with recmode data */
data->count--;
int ctdb_client_async_wait(struct ctdb_context *ctdb, struct client_async_data *data)
{
while (data->count > 0) {
- event_loop_once(ctdb->ev);
+ tevent_loop_once(ctdb->ev);
}
if (data->fail_count != 0) {
if (!data->dont_log_errors) {
* If exclude_pnn is not -1 then exclude that pnn from the list.
*/
uint32_t *list_of_nodes(struct ctdb_context *ctdb,
- struct ctdb_node_map *node_map,
+ struct ctdb_node_map_old *node_map,
TALLOC_CTX *mem_ctx,
uint32_t mask,
int exclude_pnn)
}
uint32_t *list_of_active_nodes(struct ctdb_context *ctdb,
- struct ctdb_node_map *node_map,
+ struct ctdb_node_map_old *node_map,
TALLOC_CTX *mem_ctx,
bool include_self)
{
}
uint32_t *list_of_connected_nodes(struct ctdb_context *ctdb,
- struct ctdb_node_map *node_map,
+ struct ctdb_node_map_old *node_map,
TALLOC_CTX *mem_ctx,
bool include_self)
{
return ret;
}
+static void get_capabilities_callback(struct ctdb_context *ctdb,
+ uint32_t node_pnn, int32_t res,
+ TDB_DATA outdata, void *callback_data)
+{
+ struct ctdb_node_capabilities *caps =
+ talloc_get_type(callback_data,
+ struct ctdb_node_capabilities);
+
+ if ( (outdata.dsize != sizeof(uint32_t)) || (outdata.dptr == NULL) ) {
+ DEBUG(DEBUG_ERR, (__location__ " Invalid length/pointer for getcap callback : %u %p\n", (unsigned)outdata.dsize, outdata.dptr));
+ return;
+ }
+
+ if (node_pnn >= talloc_array_length(caps)) {
+ DEBUG(DEBUG_ERR,
+ (__location__ " unexpected PNN %u\n", node_pnn));
+ return;
+ }
+
+ caps[node_pnn].retrieved = true;
+ caps[node_pnn].capabilities = *((uint32_t *)outdata.dptr);
+}
+
+struct ctdb_node_capabilities *
+ctdb_get_capabilities(struct ctdb_context *ctdb,
+ TALLOC_CTX *mem_ctx,
+ struct timeval timeout,
+ struct ctdb_node_map_old *nodemap)
+{
+ uint32_t *nodes;
+ uint32_t i, res;
+ struct ctdb_node_capabilities *ret;
+
+ nodes = list_of_connected_nodes(ctdb, nodemap, mem_ctx, true);
+
+ ret = talloc_array(mem_ctx, struct ctdb_node_capabilities,
+ nodemap->num);
+ CTDB_NO_MEMORY_NULL(ctdb, ret);
+ /* Prepopulate the expected PNNs */
+ for (i = 0; i < talloc_array_length(ret); i++) {
+ ret[i].retrieved = false;
+ }
+
+ res = ctdb_client_async_control(ctdb, CTDB_CONTROL_GET_CAPABILITIES,
+ nodes, 0, timeout,
+ false, tdb_null,
+ get_capabilities_callback, NULL,
+ ret);
+ if (res != 0) {
+ DEBUG(DEBUG_ERR,
+ (__location__ " Failed to read node capabilities.\n"));
+ TALLOC_FREE(ret);
+ }
+
+ return ret;
+}
+
+uint32_t *
+ctdb_get_node_capabilities(struct ctdb_node_capabilities *caps,
+ uint32_t pnn)
+{
+ if (pnn < talloc_array_length(caps) && caps[pnn].retrieved) {
+ return &caps[pnn].capabilities;
+ }
+
+ return NULL;
+}
+
+bool ctdb_node_has_capabilities(struct ctdb_node_capabilities *caps,
+ uint32_t pnn,
+ uint32_t capabilities_required)
+{
+ uint32_t *capp = ctdb_get_node_capabilities(caps, pnn);
+ return (capp != NULL) &&
+ ((*capp & capabilities_required) == capabilities_required);
+}
+
+
struct server_id {
uint64_t pid;
uint32_t task_id;
uint64_t unique_id;
};
-static struct server_id server_id_get(struct ctdb_context *ctdb, uint32_t reqid)
+static struct server_id server_id_fetch(struct ctdb_context *ctdb, uint32_t reqid)
{
struct server_id id;
return id;
}
-static bool server_id_equal(struct server_id *id1, struct server_id *id2)
+/* This is basically a copy from Samba's server_id.*. However, a
+ * dependency chain stops us from using Samba's version, so use a
+ * renamed copy until a better solution is found. */
+static bool ctdb_server_id_equal(struct server_id *id1, struct server_id *id2)
{
if (id1->pid != id2->pid) {
return false;
static bool server_id_exists(struct ctdb_context *ctdb, struct server_id *id)
{
- struct ctdb_server_id sid;
+ struct ctdb_client_id sid;
int ret;
- uint32_t result;
+ uint32_t result = 0;
sid.type = SERVER_TYPE_SAMBA;
sid.pnn = id->vnn;
if (data.dsize % sizeof(struct g_lock_rec) != 0) {
DEBUG(DEBUG_ERR, (__location__ "invalid data size %lu in g_lock record\n",
- data.dsize));
+ (unsigned long)data.dsize));
talloc_free(recs);
return false;
}
struct ctdb_record_handle *h;
struct g_lock_recs *locks;
struct server_id id;
+ struct timeval t_start;
int i;
key.dptr = (uint8_t *)discard_const(keyname);
key.dsize = strlen(keyname) + 1;
+
+ t_start = timeval_current();
+
+again:
+ /* Keep trying for an hour. */
+ if (timeval_elapsed(&t_start) > 3600) {
+ return false;
+ }
+
h = ctdb_fetch_lock(ctdb_db, mem_ctx, key, &data);
if (h == NULL) {
return false;
talloc_free(data.dptr);
- id = server_id_get(ctdb_db->ctdb, reqid);
+ id = server_id_fetch(ctdb_db->ctdb, reqid);
i = 0;
while (i < locks->num) {
- if (server_id_equal(&locks->lock[i].id, &id)) {
+ if (ctdb_server_id_equal(&locks->lock[i].id, &id)) {
/* Internal error */
talloc_free(h);
return false;
id.task_id, id.vnn,
(unsigned long long)id.unique_id));
talloc_free(h);
- return false;
+ goto again;
}
locks->lock = talloc_realloc(locks, locks->lock, struct g_lock_rec,
talloc_free(data.dptr);
- id = server_id_get(ctdb_db->ctdb, reqid);
+ id = server_id_fetch(ctdb_db->ctdb, reqid);
for (i=0; i<locks->num; i++) {
- if (server_id_equal(&locks->lock[i].id, &id)) {
+ if (ctdb_server_id_equal(&locks->lock[i].id, &id)) {
if (i < locks->num-1) {
locks->lock[i] = locks->lock[locks->num-1];
}
static int ctdb_transaction_destructor(struct ctdb_transaction_handle *h)
{
g_lock_unlock(h, h->g_lock_db, h->lock_name, h->reqid);
- ctdb_reqid_remove(h->ctdb_db->ctdb, h->reqid);
+ reqid_remove(h->ctdb_db->ctdb->idr, h->reqid);
return 0;
}
TALLOC_CTX *mem_ctx)
{
struct ctdb_transaction_handle *h;
- struct ctdb_server_id id;
+ struct ctdb_client_id id;
h = talloc_zero(mem_ctx, struct ctdb_transaction_handle);
if (h == NULL) {
return NULL;
}
- h->reqid = ctdb_reqid_new(h->ctdb_db->ctdb, h);
+ h->reqid = reqid_new(h->ctdb_db->ctdb->idr, h);
if (!g_lock_lock(h, h->g_lock_db, h->lock_name, h->reqid)) {
DEBUG(DEBUG_ERR, (__location__ " Error locking g_lock.tdb\n"));
return 0;
}
+ if (data.dsize == 0) {
+ *seqnum = 0;
+ return 0;
+ }
+
if (data.dsize != sizeof(*seqnum)) {
DEBUG(DEBUG_ERR, (__location__ " Invalid data recived len=%zi\n",
data.dsize));
return 0;
}
-#if 0
-/**
- * check whether a transaction is active on a given db on a given node
- */
-int32_t ctdb_ctrl_transaction_active(struct ctdb_context *ctdb,
- uint32_t destnode,
- uint32_t db_id)
-{
- int32_t status;
- int ret;
- TDB_DATA indata;
-
- indata.dptr = (uint8_t *)&db_id;
- indata.dsize = sizeof(db_id);
-
- ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_TRANS2_ACTIVE,
- 0, indata, NULL, NULL, &status,
- NULL, NULL);
-
- if (ret != 0) {
- DEBUG(DEBUG_ERR, (__location__ " ctdb control for transaction_active failed\n"));
- return -1;
- }
-
- return status;
-}
-
-
-struct ctdb_transaction_handle {
- struct ctdb_db_context *ctdb_db;
- bool in_replay;
- /*
- * we store the reads and writes done under a transaction:
- * - one list stores both reads and writes (m_all),
- * - the other just writes (m_write)
- */
- struct ctdb_marshall_buffer *m_all;
- struct ctdb_marshall_buffer *m_write;
-};
-
-/* start a transaction on a database */
-static int ctdb_transaction_destructor(struct ctdb_transaction_handle *h)
-{
- tdb_transaction_cancel(h->ctdb_db->ltdb->tdb);
- return 0;
-}
-
-/* start a transaction on a database */
-static int ctdb_transaction_fetch_start(struct ctdb_transaction_handle *h)
-{
- struct ctdb_record_handle *rh;
- TDB_DATA key;
- TDB_DATA data;
- struct ctdb_ltdb_header header;
- TALLOC_CTX *tmp_ctx;
- const char *keyname = CTDB_TRANSACTION_LOCK_KEY;
- int ret;
- struct ctdb_db_context *ctdb_db = h->ctdb_db;
- pid_t pid;
- int32_t status;
-
- key.dptr = discard_const(keyname);
- key.dsize = strlen(keyname);
-
- if (!ctdb_db->persistent) {
- DEBUG(DEBUG_ERR,(__location__ " Attempted transaction on non-persistent database\n"));
- return -1;
- }
-
-again:
- tmp_ctx = talloc_new(h);
-
- rh = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, NULL);
- if (rh == NULL) {
- DEBUG(DEBUG_ERR,(__location__ " Failed to fetch_lock database\n"));
- talloc_free(tmp_ctx);
- return -1;
- }
-
- status = ctdb_ctrl_transaction_active(ctdb_db->ctdb,
- CTDB_CURRENT_NODE,
- ctdb_db->db_id);
- if (status == 1) {
- unsigned long int usec = (1000 + random()) % 100000;
- DEBUG(DEBUG_DEBUG, (__location__ " transaction is active "
- "on db_id[0x%08x]. waiting for %lu "
- "microseconds\n",
- ctdb_db->db_id, usec));
- talloc_free(tmp_ctx);
- usleep(usec);
- goto again;
- }
-
- /*
- * store the pid in the database:
- * it is not enough that the node is dmaster...
- */
- pid = getpid();
- data.dptr = (unsigned char *)&pid;
- data.dsize = sizeof(pid_t);
- rh->header.rsn++;
- rh->header.dmaster = ctdb_db->ctdb->pnn;
- ret = ctdb_ltdb_store(ctdb_db, key, &(rh->header), data);
- if (ret != 0) {
- DEBUG(DEBUG_ERR, (__location__ " Failed to store pid in "
- "transaction record\n"));
- talloc_free(tmp_ctx);
- return -1;
- }
-
- talloc_free(rh);
-
- ret = tdb_transaction_start(ctdb_db->ltdb->tdb);
- if (ret != 0) {
- DEBUG(DEBUG_ERR,(__location__ " Failed to start tdb transaction\n"));
- talloc_free(tmp_ctx);
- return -1;
- }
-
- ret = ctdb_ltdb_fetch(ctdb_db, key, &header, tmp_ctx, &data);
- if (ret != 0) {
- DEBUG(DEBUG_ERR,(__location__ " Failed to re-fetch transaction "
- "lock record inside transaction\n"));
- tdb_transaction_cancel(ctdb_db->ltdb->tdb);
- talloc_free(tmp_ctx);
- goto again;
- }
-
- if (header.dmaster != ctdb_db->ctdb->pnn) {
- DEBUG(DEBUG_DEBUG,(__location__ " not dmaster any more on "
- "transaction lock record\n"));
- tdb_transaction_cancel(ctdb_db->ltdb->tdb);
- talloc_free(tmp_ctx);
- goto again;
- }
-
- if ((data.dsize != sizeof(pid_t)) || (*(pid_t *)(data.dptr) != pid)) {
- DEBUG(DEBUG_DEBUG, (__location__ " my pid is not stored in "
- "the transaction lock record\n"));
- tdb_transaction_cancel(ctdb_db->ltdb->tdb);
- talloc_free(tmp_ctx);
- goto again;
- }
-
- talloc_free(tmp_ctx);
-
- return 0;
-}
-
-
-/* start a transaction on a database */
-struct ctdb_transaction_handle *ctdb_transaction_start(struct ctdb_db_context *ctdb_db,
- TALLOC_CTX *mem_ctx)
-{
- struct ctdb_transaction_handle *h;
- int ret;
-
- h = talloc_zero(mem_ctx, struct ctdb_transaction_handle);
- if (h == NULL) {
- DEBUG(DEBUG_ERR,(__location__ " oom for transaction handle\n"));
- return NULL;
- }
-
- h->ctdb_db = ctdb_db;
-
- ret = ctdb_transaction_fetch_start(h);
- if (ret != 0) {
- talloc_free(h);
- return NULL;
- }
-
- talloc_set_destructor(h, ctdb_transaction_destructor);
-
- return h;
-}
-
-
-
-/*
- fetch a record inside a transaction
- */
-int ctdb_transaction_fetch(struct ctdb_transaction_handle *h,
- TALLOC_CTX *mem_ctx,
- TDB_DATA key, TDB_DATA *data)
-{
- struct ctdb_ltdb_header header;
- int ret;
-
- ZERO_STRUCT(header);
-
- ret = ctdb_ltdb_fetch(h->ctdb_db, key, &header, mem_ctx, data);
- if (ret == -1 && header.dmaster == (uint32_t)-1) {
- /* record doesn't exist yet */
- *data = tdb_null;
- ret = 0;
- }
-
- if (ret != 0) {
- return ret;
- }
-
- if (!h->in_replay) {
- h->m_all = ctdb_marshall_add(h, h->m_all, h->ctdb_db->db_id, 1, key, NULL, *data);
- if (h->m_all == NULL) {
- DEBUG(DEBUG_ERR,(__location__ " Failed to add to marshalling record\n"));
- return -1;
- }
- }
-
- return 0;
-}
-
-/*
- stores a record inside a transaction
- */
-int ctdb_transaction_store(struct ctdb_transaction_handle *h,
- TDB_DATA key, TDB_DATA data)
-{
- TALLOC_CTX *tmp_ctx = talloc_new(h);
- struct ctdb_ltdb_header header;
- TDB_DATA olddata;
- int ret;
-
- ZERO_STRUCT(header);
-
- /* we need the header so we can update the RSN */
- ret = ctdb_ltdb_fetch(h->ctdb_db, key, &header, tmp_ctx, &olddata);
- if (ret == -1 && header.dmaster == (uint32_t)-1) {
- /* the record doesn't exist - create one with us as dmaster.
- This is only safe because we are in a transaction and this
- is a persistent database */
- ZERO_STRUCT(header);
- } else if (ret != 0) {
- DEBUG(DEBUG_ERR,(__location__ " Failed to fetch record\n"));
- talloc_free(tmp_ctx);
- return ret;
- }
-
- if (data.dsize == olddata.dsize &&
- memcmp(data.dptr, olddata.dptr, data.dsize) == 0) {
- /* save writing the same data */
- talloc_free(tmp_ctx);
- return 0;
- }
-
- header.dmaster = h->ctdb_db->ctdb->pnn;
- header.rsn++;
-
- if (!h->in_replay) {
- h->m_all = ctdb_marshall_add(h, h->m_all, h->ctdb_db->db_id, 0, key, NULL, data);
- if (h->m_all == NULL) {
- DEBUG(DEBUG_ERR,(__location__ " Failed to add to marshalling record\n"));
- talloc_free(tmp_ctx);
- return -1;
- }
- }
-
- h->m_write = ctdb_marshall_add(h, h->m_write, h->ctdb_db->db_id, 0, key, &header, data);
- if (h->m_write == NULL) {
- DEBUG(DEBUG_ERR,(__location__ " Failed to add to marshalling record\n"));
- talloc_free(tmp_ctx);
- return -1;
- }
-
- ret = ctdb_ltdb_store(h->ctdb_db, key, &header, data);
-
- talloc_free(tmp_ctx);
-
- return ret;
-}
-
-/*
- replay a transaction
- */
-static int ctdb_replay_transaction(struct ctdb_transaction_handle *h)
-{
- int ret, i;
- struct ctdb_rec_data *rec = NULL;
-
- h->in_replay = true;
- talloc_free(h->m_write);
- h->m_write = NULL;
-
- ret = ctdb_transaction_fetch_start(h);
- if (ret != 0) {
- return ret;
- }
-
- for (i=0;i<h->m_all->count;i++) {
- TDB_DATA key, data;
-
- rec = ctdb_marshall_loop_next(h->m_all, rec, NULL, NULL, &key, &data);
- if (rec == NULL) {
- DEBUG(DEBUG_ERR, (__location__ " Out of records in ctdb_replay_transaction?\n"));
- goto failed;
- }
-
- if (rec->reqid == 0) {
- /* its a store */
- if (ctdb_transaction_store(h, key, data) != 0) {
- goto failed;
- }
- } else {
- TDB_DATA data2;
- TALLOC_CTX *tmp_ctx = talloc_new(h);
-
- if (ctdb_transaction_fetch(h, tmp_ctx, key, &data2) != 0) {
- talloc_free(tmp_ctx);
- goto failed;
- }
- if (data2.dsize != data.dsize ||
- memcmp(data2.dptr, data.dptr, data.dsize) != 0) {
- /* the record has changed on us - we have to give up */
- talloc_free(tmp_ctx);
- goto failed;
- }
- talloc_free(tmp_ctx);
- }
- }
-
- return 0;
-
-failed:
- tdb_transaction_cancel(h->ctdb_db->ltdb->tdb);
- return -1;
-}
-
-
-/*
- commit a transaction
- */
-int ctdb_transaction_commit(struct ctdb_transaction_handle *h)
-{
- int ret, retries=0;
- int32_t status;
- struct ctdb_context *ctdb = h->ctdb_db->ctdb;
- struct timeval timeout;
- enum ctdb_controls failure_control = CTDB_CONTROL_TRANS2_ERROR;
-
- talloc_set_destructor(h, NULL);
-
- /* our commit strategy is quite complex.
-
- - we first try to commit the changes to all other nodes
-
- - if that works, then we commit locally and we are done
-
- - if a commit on another node fails, then we need to cancel
- the transaction, then restart the transaction (thus
- opening a window of time for a pending recovery to
- complete), then replay the transaction, checking all the
- reads and writes (checking that reads give the same data,
- and writes succeed). Then we retry the transaction to the
- other nodes
- */
-
-again:
- if (h->m_write == NULL) {
- /* no changes were made */
- tdb_transaction_cancel(h->ctdb_db->ltdb->tdb);
- talloc_free(h);
- return 0;
- }
-
- /* tell ctdbd to commit to the other nodes */
- timeout = timeval_current_ofs(1, 0);
- ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, h->ctdb_db->db_id,
- retries==0?CTDB_CONTROL_TRANS2_COMMIT:CTDB_CONTROL_TRANS2_COMMIT_RETRY, 0,
- ctdb_marshall_finish(h->m_write), NULL, NULL, &status,
- &timeout, NULL);
- if (ret != 0 || status != 0) {
- tdb_transaction_cancel(h->ctdb_db->ltdb->tdb);
- DEBUG(DEBUG_NOTICE, (__location__ " transaction commit%s failed"
- ", retrying after 1 second...\n",
- (retries==0)?"":"retry "));
- sleep(1);
-
- if (ret != 0) {
- failure_control = CTDB_CONTROL_TRANS2_ERROR;
- } else {
- /* work out what error code we will give if we
- have to fail the operation */
- switch ((enum ctdb_trans2_commit_error)status) {
- case CTDB_TRANS2_COMMIT_SUCCESS:
- case CTDB_TRANS2_COMMIT_SOMEFAIL:
- case CTDB_TRANS2_COMMIT_TIMEOUT:
- failure_control = CTDB_CONTROL_TRANS2_ERROR;
- break;
- case CTDB_TRANS2_COMMIT_ALLFAIL:
- failure_control = CTDB_CONTROL_TRANS2_FINISHED;
- break;
- }
- }
-
- if (++retries == 100) {
- DEBUG(DEBUG_ERR,(__location__ " Giving up transaction on db 0x%08x after %d retries failure_control=%u\n",
- h->ctdb_db->db_id, retries, (unsigned)failure_control));
- ctdb_control(ctdb, CTDB_CURRENT_NODE, h->ctdb_db->db_id,
- failure_control, CTDB_CTRL_FLAG_NOREPLY,
- tdb_null, NULL, NULL, NULL, NULL, NULL);
- talloc_free(h);
- return -1;
- }
-
- if (ctdb_replay_transaction(h) != 0) {
- DEBUG(DEBUG_ERR, (__location__ " Failed to replay "
- "transaction on db 0x%08x, "
- "failure control =%u\n",
- h->ctdb_db->db_id,
- (unsigned)failure_control));
- ctdb_control(ctdb, CTDB_CURRENT_NODE, h->ctdb_db->db_id,
- failure_control, CTDB_CTRL_FLAG_NOREPLY,
- tdb_null, NULL, NULL, NULL, NULL, NULL);
- talloc_free(h);
- return -1;
- }
- goto again;
- } else {
- failure_control = CTDB_CONTROL_TRANS2_ERROR;
- }
-
- /* do the real commit locally */
- ret = tdb_transaction_commit(h->ctdb_db->ltdb->tdb);
- if (ret != 0) {
- DEBUG(DEBUG_ERR, (__location__ " Failed to commit transaction "
- "on db id 0x%08x locally, "
- "failure_control=%u\n",
- h->ctdb_db->db_id,
- (unsigned)failure_control));
- ctdb_control(ctdb, CTDB_CURRENT_NODE, h->ctdb_db->db_id,
- failure_control, CTDB_CTRL_FLAG_NOREPLY,
- tdb_null, NULL, NULL, NULL, NULL, NULL);
- talloc_free(h);
- return ret;
- }
-
- /* tell ctdbd that we are finished with our local commit */
- ctdb_control(ctdb, CTDB_CURRENT_NODE, h->ctdb_db->db_id,
- CTDB_CONTROL_TRANS2_FINISHED, CTDB_CTRL_FLAG_NOREPLY,
- tdb_null, NULL, NULL, NULL, NULL, NULL);
- talloc_free(h);
- return 0;
-}
-#endif
/*
recovery daemon ping to main daemon
va_end(ap);
/* get a new event context */
- ctdb->ev = event_context_init(ctdb);
+ ctdb->ev = tevent_context_init(ctdb);
tevent_loop_allow_nesting(ctdb->ev);
/* Connect to main CTDB daemon */
/*
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_eventscript_call type,
- struct ctdb_scripts_wire **scripts)
+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;
if (outdata.dsize == 0) {
*scripts = NULL;
} else {
- *scripts = (struct ctdb_scripts_wire *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
+ *scripts = (struct ctdb_script_list_old *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
talloc_free(outdata.dptr);
}
-
+
return 0;
}
return 0;
}
-int ctdb_ctrl_getstathistory(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, struct ctdb_statistics_wire **stats)
+int ctdb_ctrl_getstathistory(struct ctdb_context *ctdb,
+ struct timeval timeout, uint32_t destnode,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_statistics_list_old **stats)
{
int ret;
TDB_DATA outdata;
return -1;
}
- *stats = (struct ctdb_statistics_wire *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
+ *stats = (struct ctdb_statistics_list_old *)talloc_memdup(mem_ctx,
+ outdata.dptr,
+ outdata.dsize);
talloc_free(outdata.dptr);
-
+
return 0;
}
{
struct ctdb_client_control_state *handle;
struct ctdb_marshall_buffer *m;
- struct ctdb_rec_data *rec;
+ struct ctdb_rec_data_old *rec;
TDB_DATA outdata;
m = talloc_zero(mem_ctx, struct ctdb_marshall_buffer);