1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

use the common cmdline code in ctdbd

add a basic debug system with -dXX

(This used to be ctdb commit af9f21cef79f888c57d3b50a23ca787c9567ce60)
This commit is contained in:
Andrew Tridgell 2007-04-17 22:13:06 +10:00
parent 0d91f8043e
commit 7758511568
8 changed files with 33 additions and 68 deletions

View File

@ -53,9 +53,9 @@ bin/ctdb_test: $(OBJS) tests/ctdb_test.o tests/cmdline.o
@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 $@

View File

@ -215,6 +215,9 @@ void ctdb_recv_pkt(struct ctdb_context *ctdb, uint8_t *data, uint32_t length)
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);
@ -245,7 +248,8 @@ void ctdb_recv_pkt(struct ctdb_context *ctdb, uint8_t *data, uint32_t length)
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);
@ -257,8 +261,8 @@ void ctdb_recv_pkt(struct ctdb_context *ctdb, uint8_t *data, uint32_t length)
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));
}
/*
@ -267,8 +271,8 @@ static void ctdb_node_dead(struct ctdb_node *node)
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));
}
/*

View File

@ -276,7 +276,7 @@ void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr
return;
}
if (ret == -2) {
printf("deferring ctdb_request_dmaster\n");
DEBUG(2,(__location__ " deferring ctdb_request_dmaster\n"));
return;
}
@ -357,7 +357,7 @@ void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
return;
}
if (ret == -2) {
printf("deferred ctdb_request_call\n");
DEBUG(2,(__location__ " deferred ctdb_request_call\n"));
return;
}
@ -425,7 +425,7 @@ void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
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;
}
@ -465,7 +465,7 @@ void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
}
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;
}
@ -507,7 +507,7 @@ void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
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;
}
@ -537,7 +537,7 @@ void ctdb_reply_redirect(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
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;
}

View File

@ -78,7 +78,7 @@ void ctdb_reply_fetch_lock(struct ctdb_context *ctdb, struct ctdb_req_header *hd
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;
}
@ -139,7 +139,7 @@ static void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args)
break;
default:
printf("bogus operation code:%d\n",hdr->operation);
DEBUG(0,("bogus operation code:%d\n",hdr->operation));
}
}
@ -266,7 +266,7 @@ struct ctdb_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db,
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;
}
@ -275,7 +275,7 @@ struct ctdb_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db,
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");
@ -417,7 +417,7 @@ void ctdb_connect_wait(struct ctdb_context *ctdb)
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;
}
@ -449,7 +449,7 @@ static struct ctdb_fetch_lock_state *ctdb_client_fetch_lock_send(struct ctdb_db_
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;
@ -457,7 +457,7 @@ static struct ctdb_fetch_lock_state *ctdb_client_fetch_lock_send(struct ctdb_db_
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);
@ -559,7 +559,7 @@ struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALL
/* 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;
}
@ -590,7 +590,7 @@ struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALL
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;
}

View File

@ -25,6 +25,8 @@
#include "system/filesys.h"
#include "../include/ctdb_private.h"
int LogLevel;
/*
return error string for last error
*/

View File

@ -23,6 +23,7 @@
#include "system/filesys.h"
#include "popt.h"
#include "system/wait.h"
#include "tests/cmdline.h"
static void block_signal(int signum)
{
@ -43,21 +44,12 @@ 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
};
@ -86,45 +78,11 @@ int main(int argc, const char *argv[])
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);

View File

@ -12,7 +12,7 @@ typedef bool BOOL;
#define True 1
#define False 0
#define LogLevel 0
extern int LogLevel;
#define DEBUG(lvl, x) if ((lvl) <= LogLevel) (printf x)

View File

@ -44,6 +44,7 @@ struct poptOption popt_ctdb_cmdline[] = {
{ "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 }
};