]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
use the common cmdline code in ctdbd
authorAndrew Tridgell <tridge@samba.org>
Tue, 17 Apr 2007 12:13:06 +0000 (22:13 +1000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 17 Apr 2007 12:13:06 +0000 (22:13 +1000)
add a basic debug system with -dXX

(This used to be ctdb commit af9f21cef79f888c57d3b50a23ca787c9567ce60)

ctdb/Makefile.in
ctdb/common/ctdb.c
ctdb/common/ctdb_call.c
ctdb/common/ctdb_client.c
ctdb/common/ctdb_util.c
ctdb/direct/ctdbd.c
ctdb/include/includes.h
ctdb/tests/cmdline.c

index 52659520d528536d7b1afbe31cdea0ae13b80739..e700f4bf1e21ce568587562fea048dbaea9fe2bb 100644 (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 $@
index 0ccbecd905ef3530e03bfd109bf81bdcdb883c0a..2d3b6f79167df84a50dec621758b91f548cc0a52 100644 (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));
 }
 
 /*
index f9bbd901aa53c197a3a6fc70ff71e2ab45a4668b..65a1a5659c9a3017880a2897fc6b210950b48d55 100644 (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;
        }
 
index df2a01d86a9d0ee8f72752f1d1f90efaed7a47b7..c6071e7ba17c51ffaa93311964d54e2c23b0b800 100644 (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;
        }
index cf0c72a58b76a8720820f459a92041f5970d4523..e824e098e56cea4ef749f852cb73bb0d6fd025b7 100644 (file)
@@ -25,6 +25,8 @@
 #include "system/filesys.h"
 #include "../include/ctdb_private.h"
 
+int LogLevel;
+
 /*
   return error string for last error
 */
index 9e13c4c825a8665a74f727effdf6538ace3442eb..bfd73d551b962246c38309ae7b528f574b39d67f 100644 (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);
index e55ddc2c6b867a23254bbd68a121ffa5542a4f78..5d3207820cb08904b9ee56988e25ed5f1ad68825 100644 (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)
 
index 94d488a084a40441e0aedafcbb961d5e83e78d4e..4753d8286bc63ca9f191ad55c30a0a6af531ec91 100644 (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 }
 };