]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
- ctdb/ib minor bugfixes (error case)
authorPeter Somogyi <psomogyi@gamax.hu>
Fri, 20 Apr 2007 12:26:19 +0000 (14:26 +0200)
committerPeter Somogyi <psomogyi@gamax.hu>
Fri, 20 Apr 2007 12:26:19 +0000 (14:26 +0200)
- make ctdb capable of alternative connection (like ib) again, solved the fork problem
- do_debug memory overwrite bugfix (occured using ibwrapper_test with wrong address given)

(This used to be ctdb commit da0b84cda26d544f63841dfd770ed7ebad401944)

ctdb/common/ctdb.c
ctdb/common/ctdb_client.c
ctdb/common/ctdb_daemon.c
ctdb/ib/ibwrapper.c
ctdb/include/ctdb.h
ctdb/include/ctdb_private.h
ctdb/lib/util/debug.c
ctdb/tests/ctdb_bench.c

index 960d99011f15dd47c2d9873ed597f5704d50ade6..34f753a84d8162eef0297045d2742d819d082cf5 100644 (file)
 */
 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport)
 {
+       ctdb->transport = talloc_strdup(ctdb, transport);
+       return 0;
+}
+
+int ctdb_init_transport(struct ctdb_context *ctdb)
+{
+       int     i;
        int ctdb_tcp_init(struct ctdb_context *ctdb);
+       int     transport_found = 0;
 #ifdef USE_INFINIBAND
        int ctdb_ibw_init(struct ctdb_context *ctdb);
 #endif /* USE_INFINIBAND */
 
-       if (strcmp(transport, "tcp") == 0) {
-               return ctdb_tcp_init(ctdb);
+       if (strcmp(ctdb->transport, "tcp") == 0) {
+               transport_found = 1;
+               if (ctdb_tcp_init(ctdb))
+                       return -1;
        }
 #ifdef USE_INFINIBAND
-       if (strcmp(transport, "ib") == 0) {
-               return ctdb_ibw_init(ctdb);
+       else if (strcmp(ctdb->transport, "ib") == 0) {
+               transport_found = 1;
+               if (ctdb_ibw_init(ctdb))
+                       return -1;
        }
 #endif /* USE_INFINIBAND */
 
-       ctdb_set_error(ctdb, "Unknown transport '%s'\n", transport);
-       return -1;
+       if (!transport_found) {
+               ctdb_set_error(ctdb, "Unknown transport '%s'\n", ctdb->transport);
+               return -1;
+       }
+
+       for(i=0; i<ctdb->num_nodes; i++) {
+               if (ctdb->methods->add_node(ctdb->nodes[i]) != 0) {
+                       DEBUG(0, ("methods->add_node failed at %d\n", i));
+                       return -1;
+               }
+       }
+
+       return 0;
 }
 
 /*
@@ -116,11 +139,6 @@ static int ctdb_add_node(struct ctdb_context *ctdb, char *nstr)
           will change! */
        node->vnn = ctdb->num_nodes;
 
-       if (ctdb->methods->add_node(node) != 0) {
-               talloc_free(node);
-               return -1;
-       }
-
        if (ctdb_same_address(&ctdb->address, &node->address)) {
                ctdb->vnn = node->vnn;
        }
index f09894b55550729e9e3b01895d61c2a83c6b69c6..f7dbc230db029a1077311f4ae844d90fb9dd26e2 100644 (file)
@@ -373,7 +373,10 @@ int ctdb_set_message_handler(struct ctdb_context *ctdb, uint32_t srvid,
 
        /* if the domain socket is not yet open, open it */
        if (ctdb->daemon.sd==-1) {
-               ux_socket_connect(ctdb);
+               if (ux_socket_connect(ctdb)) {
+                       DEBUG(0, ("ux_socket_connect failed\n"));
+                       return -1;
+               }
        }
 
        ZERO_STRUCT(c);
index 6c11c7b7300fbd183fc5c22075015e5fd9d7b796..87539dc6c6c389559ac07af2f7cb08715480c9df 100644 (file)
@@ -44,6 +44,11 @@ static void daemon_incoming_packet(void *, uint8_t *, uint32_t );
 
 static void ctdb_main_loop(struct ctdb_context *ctdb)
 {
+       /* we are the dispatcher process now, so start the protocol going */
+       if (ctdb_init_transport(ctdb)) {
+               exit(1);
+       }
+
        ctdb->methods->start(ctdb);
 
        /* go into a wait loop to allow other nodes to complete */
@@ -594,6 +599,12 @@ int ctdb_start(struct ctdb_context *ctdb)
                close(fd[0]);
                close(ctdb->daemon.sd);
                ctdb->daemon.sd = -1;
+
+               /* Added because of ctdb->methods->allocate_pkt calls */
+               /* TODO: clean */
+               int ctdb_tcp_init(struct ctdb_context *ctdb);
+               ctdb_tcp_init(ctdb);
+
                return 0;
        }
 
index f7b233954d229ce6faf73747e6b711e3ddf28cdb..908d38d58406a7803e4130d6e07ba636d54ac122 100644 (file)
@@ -557,17 +557,17 @@ static void ibw_event_handler_cm(struct event_context *ev,
        return;
 error:
        if (event!=NULL && (rc=rdma_ack_cm_event(event))) {
-               sprintf(ibw_lasterr, "rdma_ack_cm_event failed with %d\n", rc);
-               goto error;
+               DEBUG(0, ("rdma_ack_cm_event failed with %d\n", rc));
        }
 
        DEBUG(0, ("cm event handler: %s", ibw_lasterr));
 
        if (cma_id!=pctx->cm_id) {
                conn = talloc_get_type(cma_id->context, struct ibw_conn);
-               if (conn)
+               if (conn) {
                        conn->state = IBWC_ERROR;
-               pctx->connstate_func(NULL, conn);
+                       pctx->connstate_func(NULL, conn);
+               }
        } else {
                ctx->state = IBWS_ERROR;
                pctx->connstate_func(ctx, NULL);
index 997bdc6e13f326740f80f47f15517cc6b979e141..7c4e6d25f7a844a0fc4cb3ff7b8a5f45528cc0f7 100644 (file)
@@ -70,6 +70,12 @@ struct ctdb_context *ctdb_init(struct event_context *ev);
 */
 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
 
+/*
+  initialize the chosen transport
+  do this in the process where it is going to be used
+ */
+int ctdb_init_transport(struct ctdb_context *ctdb);
+
 /*
   set the directory for the local databases
 */
index 2f42cfb88a07d1413e761ef79c469e2741a24936..cf6d24cc411d86be040e1ebc21d8555fc5ba8a0e 100644 (file)
@@ -120,6 +120,7 @@ struct ctdb_context {
        struct ctdb_address address;
        const char *name;
        const char *db_directory;
+       char *transport;
        uint32_t vnn; /* our own vnn */
        uint32_t num_nodes;
        uint32_t num_connected;
@@ -362,6 +363,11 @@ int ctdbd_start(struct ctdb_context *ctdb);
 struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
 int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
 
+/*
+  allocate a packet for sending via queue
+*/
+void *ctdb_queue_allocate_pkt(TALLOC_CTX *mem_ctx, size_t size);
+
 /*
   queue a packet for sending
 */
index a3229015ca857ef6b1dd2936163a6d75903380a9..ffe1dcc382fb4896048c313f81f363eb9437b5a3 100644 (file)
 #include "system/time.h"
 #include <unistd.h>
 
+static int vasprintf2(char **ptr, const char *format, va_list ap)
+{
+    int ret;
+    va_list tmp_ap;
+
+    va_copy(tmp_ap, ap);
+    ret = vsnprintf(NULL, 0, format, tmp_ap);
+    if (ret <= 0) return ret;
+
+    (*ptr) = (char *)malloc(ret+1);
+    if (!*ptr) return -1;
+    ret = vsnprintf(*ptr, ret+1, format, ap);
+
+    return ret;
+}
+
 void do_debug(const char *format, ...)
 {
        struct timeval tm;
@@ -29,7 +45,7 @@ void do_debug(const char *format, ...)
        char *s = NULL;
 
        va_start(ap, format);
-       vasprintf(&s, format, ap);
+       vasprintf2(&s, format, ap);
        va_end(ap);
 
        gettimeofday(&tm, NULL);
index 02fcc1f2d458234363c095505a9dde534e1c1206..ead3184157e28442a52b5ef8ecf430ce0a74e543 100644 (file)
@@ -204,7 +204,8 @@ int main(int argc, const char *argv[])
        /* start the protocol running */
        ret = ctdb_start(ctdb);
 
-       ctdb_set_message_handler(ctdb, 0, ring_message_handler,&msg_count);
+       if (ctdb_set_message_handler(ctdb, 0, ring_message_handler,&msg_count))
+               goto error;
 
        /* wait until all nodes are connected (should not be needed
           outside of test code) */
@@ -212,6 +213,7 @@ int main(int argc, const char *argv[])
 
        bench_ring(ctdb, ev);
        
+error:
        /* shut it down */
        ctdb_shutdown(ctdb);