#include <stdlib.h>
#include "../include/ctdb_private.h"
#include "lib/util/dlinklist.h"
+#include "common/reqid.h"
/*
allocate a packet for use in client<->daemon communication
struct ctdb_reply_call *c = (struct ctdb_reply_call *)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;
*/
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;
}
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);
struct ctdb_reply_control *c = (struct ctdb_reply_control *)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;
*/
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;
}
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;
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) {
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;
}
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"));
#include "system/filesys.h"
#include "system/wait.h"
#include "../include/ctdb_private.h"
+#include "common/reqid.h"
/*
return error string for last error
return tdb_jenkins_hash(discard_const(key));
}
-/*
- a type checking varient of idr_find
- */
-static void *_idr_find_type(struct idr_context *idp, int id, const char *type, const char *location)
-{
- void *p = idr_find(idp, id);
- if (p && talloc_check_name(p, type) == NULL) {
- DEBUG(DEBUG_ERR,("%s idr_find_type expected type %s but got %s\n",
- location, type, talloc_get_name(p)));
- return NULL;
- }
- return p;
-}
-
-uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state)
-{
- int id = idr_get_new_above(ctdb->idr, state, ctdb->lastid+1, INT_MAX);
- if (id < 0) {
- DEBUG(DEBUG_DEBUG, ("Reqid wrap!\n"));
- id = idr_get_new(ctdb->idr, state, INT_MAX);
- }
- ctdb->lastid = id;
- return id;
-}
-
-void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *type, const char *location)
-{
- void *p;
-
- p = _idr_find_type(ctdb->idr, reqid, type, location);
- if (p == NULL) {
- DEBUG(DEBUG_WARNING, ("Could not find idr:%u\n",reqid));
- }
-
- return p;
-}
-
-
-void ctdb_reqid_remove(struct ctdb_context *ctdb, uint32_t reqid)
-{
- int ret;
-
- ret = idr_remove(ctdb->idr, reqid);
- if (ret != 0) {
- DEBUG(DEBUG_ERR, ("Removing idr that does not exist\n"));
- }
-}
-
static uint32_t ctdb_marshall_record_size(TDB_DATA key,
struct ctdb_ltdb_header *header,
uint32_t num_connected;
unsigned flags;
uint32_t capabilities;
- struct idr_context *idr;
- int lastid;
+ struct reqid_context *idr;
struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
struct ctdb_vnn *vnn; /* list of public ip addresses and interfaces */
struct ctdb_vnn *single_ip_vnn; /* a structure for the single ip */
int ctdb_socket_connect(struct ctdb_context *ctdb);
void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args);
-uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state);
-void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *type, const char *location);
-void ctdb_reqid_remove(struct ctdb_context *ctdb, uint32_t reqid);
-
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);
#include "system/filesys.h"
#include "../include/ctdb_private.h"
#include "../common/rb_tree.h"
+#include "common/reqid.h"
struct ctdb_sticky_record {
struct ctdb_context *ctdb;
header.dmaster = ctdb->pnn;
header.flags = record_flags;
- state = ctdb_reqid_find(ctdb, hdr->reqid, struct ctdb_call_state);
+ state = reqid_find(ctdb->idr, hdr->reqid, struct ctdb_call_state);
if (state) {
if (state->call->flags & CTDB_CALL_FLAG_VACUUM_MIGRATION) {
struct ctdb_reply_call *c = (struct ctdb_reply_call *)hdr;
struct ctdb_call_state *state;
- state = ctdb_reqid_find(ctdb, hdr->reqid, struct ctdb_call_state);
+ state = reqid_find(ctdb->idr, hdr->reqid, struct ctdb_call_state);
if (state == NULL) {
DEBUG(DEBUG_ERR, (__location__ " reqid %u not found\n", hdr->reqid));
return;
struct ctdb_reply_error *c = (struct ctdb_reply_error *)hdr;
struct ctdb_call_state *state;
- state = ctdb_reqid_find(ctdb, hdr->reqid, struct ctdb_call_state);
+ state = reqid_find(ctdb->idr, hdr->reqid, struct ctdb_call_state);
if (state == NULL) {
DEBUG(DEBUG_ERR,("pnn %u Invalid reqid %u in ctdb_reply_error\n",
ctdb->pnn, hdr->reqid));
static int ctdb_call_destructor(struct ctdb_call_state *state)
{
DLIST_REMOVE(state->ctdb_db->pending_calls, state);
- ctdb_reqid_remove(state->ctdb_db->ctdb, state->reqid);
+ reqid_remove(state->ctdb_db->ctdb->idr, state->reqid);
return 0;
}
state->generation = state->ctdb_db->generation;
/* use a new reqid, in case the old reply does eventually come in */
- ctdb_reqid_remove(ctdb, state->reqid);
- state->reqid = ctdb_reqid_new(ctdb, state);
+ reqid_remove(ctdb->idr, state->reqid);
+ state->reqid = reqid_new(ctdb->idr, state);
state->c->hdr.reqid = state->reqid;
/* update the generation count for this request, so its valid with the new vnn_map */
state->call = talloc(state, struct ctdb_call);
CTDB_NO_MEMORY_NULL(ctdb, state->call);
- state->reqid = ctdb_reqid_new(ctdb, state);
+ state->reqid = reqid_new(ctdb->idr, state);
state->ctdb_db = ctdb_db;
talloc_set_destructor(state, ctdb_call_destructor);
#include "lib/util/dlinklist.h"
#include "lib/tdb_wrap/tdb_wrap.h"
#include "lib/util/talloc_report.h"
+#include "common/reqid.h"
struct ctdb_control_state {
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));
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;
}
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;
#include "../include/ctdb_private.h"
#include "../common/rb_tree.h"
#include <sys/socket.h>
+#include "common/reqid.h"
struct ctdb_client_pid_list {
struct ctdb_client_pid_list *next, *prev;
*/
int daemon_register_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid)
{
- struct ctdb_client *client = ctdb_reqid_find(ctdb, client_id, struct ctdb_client);
+ struct ctdb_client *client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
int res;
if (client == NULL) {
DEBUG(DEBUG_ERR,("Bad client_id in daemon_request_register_message_handler\n"));
*/
int daemon_deregister_message_handler(struct ctdb_context *ctdb, uint32_t client_id, uint64_t srvid)
{
- struct ctdb_client *client = ctdb_reqid_find(ctdb, client_id, struct ctdb_client);
+ struct ctdb_client *client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
if (client == NULL) {
DEBUG(DEBUG_ERR,("Bad client_id in daemon_request_deregister_message_handler\n"));
return -1;
struct ctdb_db_context *ctdb_db;
ctdb_takeover_client_destructor_hook(client);
- ctdb_reqid_remove(client->ctdb, client->client_id);
+ reqid_remove(client->ctdb->idr, client->client_id);
client->ctdb->num_clients--;
if (client->num_persistent_updates != 0) {
return;
}
- client = ctdb_reqid_find(w->ctdb, w->client_id, struct ctdb_client);
+ client = reqid_find(w->ctdb->idr, w->client_id, struct ctdb_client);
if (client == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Packet for disconnected client %u\n",
w->client_id));
DLIST_REMOVE(dfq->deferred_calls, dfc);
- client = ctdb_reqid_find(dfc->w->ctdb, dfc->w->client_id, struct ctdb_client);
+ client = reqid_find(dfc->w->ctdb->idr, dfc->w->client_id, struct ctdb_client);
if (client == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Packet for disconnected client %u\n",
dfc->w->client_id));
client->ctdb = ctdb;
client->fd = fd;
- client->client_id = ctdb_reqid_new(ctdb, client);
+ client->client_id = reqid_new(ctdb->idr, client);
client->pid = peer_pid;
client_pid = talloc(client, struct ctdb_client_pid_list);
int32_t ctdb_control_register_notify(struct ctdb_context *ctdb, uint32_t client_id, TDB_DATA indata)
{
struct ctdb_client_notify_register *notify = (struct ctdb_client_notify_register *)indata.dptr;
- struct ctdb_client *client = ctdb_reqid_find(ctdb, client_id, struct ctdb_client);
+ struct ctdb_client *client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
struct ctdb_client_notify_list *nl;
DEBUG(DEBUG_INFO,("Register srvid %llu for client %d\n", (unsigned long long)notify->srvid, client_id));
int32_t ctdb_control_deregister_notify(struct ctdb_context *ctdb, uint32_t client_id, TDB_DATA indata)
{
struct ctdb_client_notify_deregister *notify = (struct ctdb_client_notify_deregister *)indata.dptr;
- struct ctdb_client *client = ctdb_reqid_find(ctdb, client_id, struct ctdb_client);
+ struct ctdb_client *client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
struct ctdb_client_notify_list *nl;
DEBUG(DEBUG_INFO,("Deregister srvid %llu for client %d\n", (unsigned long long)notify->srvid, client_id));
#include "lib/tdb_wrap/tdb_wrap.h"
#include "lib/util/dlinklist.h"
#include <ctype.h>
+#include "common/reqid.h"
#define PERSISTENT_HEALTH_TDB "persistent_health.tdb"
* recovery daemons.
*/
if (client_id != 0) {
- client = ctdb_reqid_find(ctdb, client_id, struct ctdb_client);
+ client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
}
if (client != NULL) {
/* If the node is inactive it is not part of the cluster
* Do the actual detach only if the control comes from other daemons.
*/
if (client_id != 0) {
- client = ctdb_reqid_find(ctdb, client_id, struct ctdb_client);
+ client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
if (client != NULL) {
/* forward the control to all the nodes */
ctdb_daemon_send_control(ctdb, CTDB_BROADCAST_ALL, 0,
#include "lib/tdb_wrap/tdb_wrap.h"
#include "tdb.h"
#include "../include/ctdb_private.h"
+#include "common/reqid.h"
struct ctdb_persistent_state {
struct ctdb_context *ctdb;
return -1;
}
- client = ctdb_reqid_find(ctdb, c->client_id, struct ctdb_client);
+ client = reqid_find(ctdb->idr, c->client_id, struct ctdb_client);
if (client == NULL) {
DEBUG(DEBUG_ERR,(__location__ " can not match persistent_store "
"to a client. Returning error\n"));
struct ctdb_req_control *c,
TDB_DATA recdata)
{
- struct ctdb_client *client = ctdb_reqid_find(ctdb, c->client_id, struct ctdb_client);
+ struct ctdb_client *client = reqid_find(ctdb->idr, c->client_id, struct ctdb_client);
if (client == NULL) {
DEBUG(DEBUG_ERR,(__location__ " can not match start_persistent_update to a client. Returning error\n"));
struct ctdb_req_control *c,
TDB_DATA recdata)
{
- struct ctdb_client *client = ctdb_reqid_find(ctdb, c->client_id, struct ctdb_client);
+ struct ctdb_client *client = reqid_find(ctdb->idr, c->client_id, struct ctdb_client);
if (client == NULL) {
DEBUG(DEBUG_ERR,(__location__ " can not match cancel_persistent_update to a client. Returning error\n"));
#include "includes.h"
#include "../include/ctdb_private.h"
#include "../common/rb_tree.h"
+#include "common/reqid.h"
#define SERVER_ID_KEY_SIZE 3
TDB_DATA indata)
{
struct ctdb_server_id *server_id;
- struct ctdb_client *client = ctdb_reqid_find(ctdb, client_id, struct ctdb_client);
+ struct ctdb_client *client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
if (client == NULL) {
#include "system/wait.h"
#include "../include/ctdb_private.h"
#include "../common/rb_tree.h"
+#include "common/reqid.h"
#define TAKEOVER_TIMEOUT() timeval_current_ofs(ctdb->tunable.takeover_timeout,0)
ctdb_addr_to_str(&ip->addr)));
if (ctdb_same_ip(&tmp_addr, addr)) {
- struct ctdb_client *client = ctdb_reqid_find(ctdb,
- ip->client_id,
- struct ctdb_client);
+ struct ctdb_client *client = reqid_find(ctdb->idr,
+ ip->client_id,
+ struct ctdb_client);
DEBUG(DEBUG_INFO,("matched client %u with IP %s and pid %u\n",
ip->client_id,
ctdb_addr_to_str(&ip->addr),
int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id,
TDB_DATA indata)
{
- struct ctdb_client *client = ctdb_reqid_find(ctdb, client_id, struct ctdb_client);
+ struct ctdb_client *client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
struct ctdb_control_tcp_addr *tcp_sock = NULL;
struct ctdb_tcp_list *tcp;
struct ctdb_tcp_connection t;
#include "tdb.h"
#include "../include/ctdb_private.h"
#include "lib/util/dlinklist.h"
+#include "common/reqid.h"
typedef void (*ctdb_traverse_fn_t)(void *private_data, TDB_DATA key, TDB_DATA data);
*/
static int ctdb_traverse_all_destructor(struct ctdb_traverse_all_handle *state)
{
- ctdb_reqid_remove(state->ctdb, state->reqid);
+ reqid_remove(state->ctdb->idr, state->reqid);
return 0;
}
state->ctdb = ctdb;
state->ctdb_db = ctdb_db;
- state->reqid = ctdb_reqid_new(ctdb_db->ctdb, state);
+ state->reqid = reqid_new(ctdb_db->ctdb->idr, state);
state->callback = callback;
state->private_data = start_state;
state->null_count = 0;
return -1;
}
- state = ctdb_reqid_find(ctdb, d->reqid, struct ctdb_traverse_all_handle);
+ state = reqid_find(ctdb->idr, d->reqid, struct ctdb_traverse_all_handle);
if (state == NULL || d->reqid != state->reqid) {
/* traverse might have been terminated already */
return -1;
struct ctdb_traverse_start_ext *d = (struct ctdb_traverse_start_ext *)data.dptr;
struct traverse_start_state *state;
struct ctdb_db_context *ctdb_db;
- struct ctdb_client *client = ctdb_reqid_find(ctdb, client_id, struct ctdb_client);
+ struct ctdb_client *client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
if (client == NULL) {
DEBUG(DEBUG_ERR,(__location__ " No client found\n"));
#include "system/network.h"
#include "cmdline.h"
#include "../include/ctdb_private.h"
+#include "common/reqid.h"
static struct {
const char *nlist;
ctdb->recovery_mode = CTDB_RECOVERY_NORMAL;
ctdb->recovery_master = (uint32_t)-1;
ctdb->upcalls = &ctdb_upcalls;
- ctdb->idr = idr_init(ctdb);
ctdb->recovery_lock_fd = -1;
+ ret = reqid_init(ctdb, 0, &ctdb->idr);;
+ if (ret != 0) {
+ DEBUG(DEBUG_ALERT, ("reqid_init failed (%s)\n", strerror(ret)));
+ exit(1);
+ }
+
ctdb_tunables_set_defaults(ctdb);
ret = ctdb_set_recovery_lock_file(ctdb, options.recovery_lock_file);
#include "common/ctdb_logging.c"
#include "common/ctdb_fork.c"
#include "common/system_util.c"
+#include "common/reqid.c"
/* CTDB_CLIENT_OBJ */
#include "client/ctdb_client.c"
#include "common/ctdb_logging.c"
#include "common/ctdb_fork.c"
#include "common/system_util.c"
+#include "common/reqid.c"
/* CTDB_SERVER_OBJ */
#include "server/ctdb_daemon.c"