]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
change the tcp code to call ctdb_read_pdu() instead of doing the partial read thing...
authorRonnie sahlberg <ronniesahlberg@gmail.com>
Tue, 10 Apr 2007 03:17:15 +0000 (13:17 +1000)
committerRonnie sahlberg <ronniesahlberg@gmail.com>
Tue, 10 Apr 2007 03:17:15 +0000 (13:17 +1000)
(This used to be ctdb commit 6156bec0187df27578afd5afa3fcaadb1a202030)

ctdb/common/ctdb.c
ctdb/tcp/ctdb_tcp.h
ctdb/tcp/tcp_io.c

index d8b4859232dddadad2e0a4469309f5de2a1daaac..ff0829ba4dcdb3bdff5c74bf4cfb0498ab68ec24 100644 (file)
@@ -340,8 +340,6 @@ struct ctdb_context *ctdb_init(struct event_context *ev)
 
 int ctdb_start(struct ctdb_context *ctdb)
 {
-       int res;
-
        if (ctdb->flags&CTDB_FLAG_DAEMON_MODE) {
                return ctdbd_start(ctdb);
        }
index 0f8ce300b446410201204910c5e05fa187ad84e2..5b6cd299b9295b6154804f101adced848b7b30ce 100644 (file)
@@ -24,23 +24,13 @@ struct ctdb_tcp {
        int listen_fd;
 };
 
-/*
-  incoming packet structure - only used when we get a partial packet
-  on read
-*/
-struct ctdb_tcp_partial {
-       uint8_t *data;
-       uint32_t length;
-};
-
-
 /*
   state associated with an incoming connection
 */
 struct ctdb_incoming {
        struct ctdb_context *ctdb;
        int fd;
-       struct ctdb_tcp_partial partial;
+       struct ctdb_partial partial;
 };
 
 /*
index e59f6167ff8a15798b9eb53ed3c9a08571e51f59..22771669869b3dc5380a735d4bab8ec0f69b3da9 100644 (file)
@@ -98,92 +98,47 @@ void ctdb_tcp_node_write(struct event_context *ev, struct fd_event *fde,
 }
 
 
-/*
-  called when an incoming connection is readable
-*/
-void ctdb_tcp_incoming_read(struct event_context *ev, struct fd_event *fde, 
-                           uint16_t flags, void *private)
+
+static void tcp_read_cb(uint8_t *data, int cnt, void *args)
 {
-       struct ctdb_incoming *in = talloc_get_type(private, struct ctdb_incoming);
-       int num_ready = 0;
-       ssize_t nread;
-       uint8_t *data, *data_base;
-
-       if (ioctl(in->fd, FIONREAD, &num_ready) != 0 ||
-           num_ready == 0) {
-               /* we've lost the link from another node. We don't
-                  notify the upper layers, as we only want to trigger
-                  a full node reorganisation when a send fails - that
-                  allows nodes to restart without penalty as long as
-                  the network is idle */
-               talloc_free(in);
+       struct ctdb_incoming *in = talloc_get_type(args, struct ctdb_incoming);
+       struct ctdb_req_header *hdr;
+
+       if (cnt < sizeof(*hdr)) {
+               ctdb_set_error(in->ctdb, "Bad packet length %d\n", cnt);
                return;
        }
-
-       in->partial.data = talloc_realloc_size(in, in->partial.data, 
-                                              num_ready + in->partial.length);
-       if (in->partial.data == NULL) {
-               /* not much we can do except drop the socket */
-               talloc_free(in);
+       hdr = (struct ctdb_req_header *)data;
+       if (cnt != hdr->length) {
+               ctdb_set_error(in->ctdb, "Bad header length %d expected %d\n", 
+                              hdr->length, cnt);
                return;
        }
 
-       nread = read(in->fd, in->partial.data+in->partial.length, num_ready);
-       if (nread <= 0) {
-               /* the connection must be dead */
-               talloc_free(in);
+       if (hdr->ctdb_magic != CTDB_MAGIC) {
+               ctdb_set_error(in->ctdb, "Non CTDB packet rejected\n");
                return;
        }
 
-       data = in->partial.data;
-       nread += in->partial.length;
-
-       in->partial.data = NULL;
-       in->partial.length = 0;
-
-       if (nread >= 4 && *(uint32_t *)data == nread) {
-               /* most common case - we got a whole packet in one go
-                  tell the ctdb layer above that we have a packet */
-               in->ctdb->upcalls->recv_pkt(in->ctdb, data, nread);
+       if (hdr->ctdb_version != CTDB_VERSION) {
+               ctdb_set_error(in->ctdb, "Bad CTDB version 0x%x rejected\n", hdr->ctdb_version);
                return;
        }
 
-       data_base = data;
-
-       while (nread >= 4 && *(uint32_t *)data <= nread) {
-               /* we have at least one packet */
-               uint8_t *d2;
-               uint32_t len;
-               len = *(uint32_t *)data;
-               d2 = talloc_memdup(in, data, len);
-               if (d2 == NULL) {
-                       /* sigh */
-                       talloc_free(in);
-                       return;
-               }
-               in->ctdb->upcalls->recv_pkt(in->ctdb, d2, len);
-               data += len;
-               nread -= len;           
-       }
+       /* most common case - we got a whole packet in one go
+          tell the ctdb layer above that we have a packet */
+       in->ctdb->upcalls->recv_pkt(in->ctdb, data, cnt);
+}
 
-       if (nread > 0) {
-               /* we have only part of a packet */
-               if (data_base == data) {
-                       in->partial.data = data;
-                       in->partial.length = nread;
-               } else {
-                       in->partial.data = talloc_memdup(in, data, nread);
-                       if (in->partial.data == NULL) {
-                               talloc_free(in);
-                               return;
-                       }
-                       in->partial.length = nread;
-                       talloc_free(data_base);
-               }
-               return;
-       }
+/*
+  called when an incoming connection is readable
+*/
+void ctdb_tcp_incoming_read(struct event_context *ev, struct fd_event *fde, 
+                           uint16_t flags, void *private)
+{
+       struct ctdb_incoming *in = talloc_get_type(private, struct ctdb_incoming);
 
-       talloc_free(data_base);
+       ctdb_read_pdu(in->fd, in, &in->partial, tcp_read_cb, in);
 }
 
 /*