@echo Linking $@
@$(CC) $(CFLAGS) -o $@ tests/ctdb_test.o tests/cmdline.o $(OBJS) $(LIB_FLAGS)
-bin/ctdbd: $(OBJS) direct/ctdbd.o
+bin/ctdbd: $(OBJS) direct/ctdbd.o tests/cmdline.o
@echo Linking $@
- @$(CC) $(CFLAGS) -o $@ direct/ctdbd.o $(OBJS) $(LIB_FLAGS)
+ @$(CC) $(CFLAGS) -o $@ direct/ctdbd.o tests/cmdline.o $(OBJS) $(LIB_FLAGS)
bin/ctdbd_test: $(OBJS) direct/ctdbd_test.o
@echo Linking $@
return;
}
+ DEBUG(3,(__location__ " ctdb request of type %d length %d from node %d to %d\n",
+ hdr->operation, hdr->length, hdr->srcnode, hdr->destnode));
+
switch (hdr->operation) {
case CTDB_REQ_CALL:
ctdb_request_call(ctdb, hdr);
break;
default:
- printf("Packet with unknown operation %d\n", hdr->operation);
+ DEBUG(0,("%s: Packet with unknown operation %d\n",
+ __location__, hdr->operation));
break;
}
talloc_free(hdr);
static void ctdb_node_dead(struct ctdb_node *node)
{
node->ctdb->num_connected--;
- printf("%s: node %s is dead: %d connected\n",
- node->ctdb->name, node->name, node->ctdb->num_connected);
+ DEBUG(1,("%s: node %s is dead: %d connected\n",
+ node->ctdb->name, node->name, node->ctdb->num_connected));
}
/*
static void ctdb_node_connected(struct ctdb_node *node)
{
node->ctdb->num_connected++;
- printf("%s: connected to %s - %d connected\n",
- node->ctdb->name, node->name, node->ctdb->num_connected);
+ DEBUG(1,("%s: connected to %s - %d connected\n",
+ node->ctdb->name, node->name, node->ctdb->num_connected));
}
/*
return;
}
if (ret == -2) {
- printf("deferring ctdb_request_dmaster\n");
+ DEBUG(2,(__location__ " deferring ctdb_request_dmaster\n"));
return;
}
return;
}
if (ret == -2) {
- printf("deferred ctdb_request_call\n");
+ DEBUG(2,(__location__ " deferred ctdb_request_call\n"));
return;
}
if (state == NULL) return;
if (!talloc_get_type(state, struct ctdb_call_state)) {
- printf("ctdb idr type error at %s\n", __location__);
+ DEBUG(0,("ctdb idr type error at %s\n", __location__));
return;
}
}
if (!talloc_get_type(state, struct ctdb_call_state)) {
- printf("ctdb idr type error at %s\n", __location__);
+ DEBUG(0,("ctdb idr type error at %s\n", __location__));
return;
}
if (state == NULL) return;
if (!talloc_get_type(state, struct ctdb_call_state)) {
- printf("ctdb idr type error at %s\n", __location__);
+ DEBUG(0,("ctdb idr type error at %s\n", __location__));
return;
}
if (state == NULL) return;
if (!talloc_get_type(state, struct ctdb_call_state)) {
- printf("ctdb idr type error at %s\n", __location__);
+ DEBUG(0,("ctdb idr type error at %s\n", __location__));
return;
}
if (state == NULL) return;
if (!talloc_get_type(state, struct ctdb_fetch_lock_state)) {
- printf("ctdb idr type error at %s\n", __location__);
+ DEBUG(0, ("ctdb idr type error at %s\n", __location__));
return;
}
break;
default:
- printf("bogus operation code:%d\n",hdr->operation);
+ DEBUG(0,("bogus operation code:%d\n",hdr->operation));
}
}
state = talloc_zero(ctdb_db, struct ctdb_call_state);
if (state == NULL) {
- printf("failed to allocate state\n");
+ DEBUG(0, (__location__ " failed to allocate state\n"));
return NULL;
}
len = offsetof(struct ctdb_req_call, data) + call->key.dsize + call->call_data.dsize;
state->c = ctdbd_allocate_pkt(ctdb, len);
if (state->c == NULL) {
- printf("failed to allocate packet\n");
+ DEBUG(0, (__location__ " failed to allocate packet\n"));
return NULL;
}
talloc_set_name_const(state->c, "ctdbd req_call packet");
res = ctdb_queue_send(ctdb->daemon.queue, (uint8_t *)&r.hdr, r.hdr.length);
if (res != 0) {
- printf("Failed to queue a connect wait request\n");
+ DEBUG(0,(__location__ " Failed to queue a connect wait request\n"));
return;
}
state = talloc_zero(ctdb_db, struct ctdb_fetch_lock_state);
if (state == NULL) {
- printf("failed to allocate state\n");
+ DEBUG(0, (__location__ " failed to allocate state\n"));
return NULL;
}
state->state = CTDB_FETCH_LOCK_WAIT;
len = offsetof(struct ctdb_req_fetch_lock, key) + key.dsize;
state->req = req = ctdbd_allocate_pkt(ctdb, len);
if (req == NULL) {
- printf("failed to allocate packet\n");
+ DEBUG(0, (__location__ " failed to allocate packet\n"));
return NULL;
}
ZERO_STRUCT(*req);
/* step 1 - get the chain lock */
ret = ctdb_ltdb_lock(ctdb_db, key);
if (ret != 0) {
- printf("failed to lock ltdb record\n");
+ DEBUG(0, (__location__ " failed to lock ltdb record\n"));
talloc_free(h);
return NULL;
}
h->header.dmaster = ctdb_db->ctdb->vnn;
ret = ctdb_ltdb_store(ctdb_db, key, &h->header, *data);
if (ret != 0) {
- printf("bugger - we're in real trouble now! can't update record to mark us as dmasterx\n");
+ DEBUG(0, (__location__" can't update record to mark us as dmaster\n"));
talloc_free(h);
return NULL;
}
#include "system/filesys.h"
#include "../include/ctdb_private.h"
+int LogLevel;
+
/*
return error string for last error
*/
#include "system/filesys.h"
#include "popt.h"
#include "system/wait.h"
+#include "tests/cmdline.h"
static void block_signal(int signum)
{
int main(int argc, const char *argv[])
{
struct ctdb_context *ctdb;
- const char *nlist = NULL;
- const char *transport = "tcp";
- const char *myaddress = NULL;
- int self_connect=0;
- int daemon_mode=0;
const char *db_list = "test.tdb";
char *s, *tok;
struct poptOption popt_options[] = {
POPT_AUTOHELP
- { "nlist", 0, POPT_ARG_STRING, &nlist, 0, "node list file", "filename" },
- { "listen", 0, POPT_ARG_STRING, &myaddress, 0, "address to listen on", "address" },
- { "transport", 0, POPT_ARG_STRING, &transport, 0, "protocol transport", NULL },
- { "self-connect", 0, POPT_ARG_NONE, &self_connect, 0, "enable self connect", "boolean" },
- { "daemon", 0, POPT_ARG_NONE, &daemon_mode, 0, "spawn a ctdb daemon", "boolean" },
+ POPT_CTDB_CMDLINE
{ "dblist", 0, POPT_ARG_STRING, &db_list, 0, "list of databases", NULL },
POPT_TABLEEND
};
while (extra_argv[extra_argc]) extra_argc++;
}
- if (nlist == NULL || myaddress == NULL) {
- printf("You must provide a node list with --nlist and an address with --listen\n");
- exit(1);
- }
-
block_signal(SIGPIPE);
ev = event_context_init(NULL);
- /* initialise ctdb */
- ctdb = ctdb_init(ev);
- if (ctdb == NULL) {
- printf("Failed to init ctdb\n");
- exit(1);
- }
-
- if (self_connect) {
- ctdb_set_flags(ctdb, CTDB_FLAG_SELF_CONNECT);
- }
-
- ret = ctdb_set_transport(ctdb, transport);
- if (ret == -1) {
- printf("ctdb_set_transport failed - %s\n", ctdb_errstr(ctdb));
- exit(1);
- }
-
- /* tell ctdb what address to listen on */
- ret = ctdb_set_address(ctdb, myaddress);
- if (ret == -1) {
- printf("ctdb_set_address failed - %s\n", ctdb_errstr(ctdb));
- exit(1);
- }
-
- /* tell ctdb what nodes are available */
- ret = ctdb_set_nlist(ctdb, nlist);
- if (ret == -1) {
- printf("ctdb_set_nlist failed - %s\n", ctdb_errstr(ctdb));
- exit(1);
- }
+ ctdb = ctdb_cmdline_init(ev);
/* attach to the list of databases */
s = talloc_strdup(ctdb, db_list);
#define True 1
#define False 0
-#define LogLevel 0
+extern int LogLevel;
#define DEBUG(lvl, x) if ((lvl) <= LogLevel) (printf x)
{ "listen", 0, POPT_ARG_STRING, &ctdb_cmdline.myaddress, 0, "address to listen on", "address" },
{ "transport", 0, POPT_ARG_STRING, &ctdb_cmdline.transport, 0, "protocol transport", NULL },
{ "self-connect", 0, POPT_ARG_NONE, &ctdb_cmdline.self_connect, 0, "enable self connect", "boolean" },
+ { "debug", 'd', POPT_ARG_INT, &LogLevel, 0, "debug level"},
{ NULL }
};