------------------------------------------------------------
revno: 762
revision-id:[EMAIL PROTECTED]
parent: [EMAIL PROTECTED]
committer: Andrew Tridgell <[EMAIL PROTECTED]>
branch nick: tridge.stable
timestamp: Wed 2008-01-16 09:44:48 +1100
message:
  - catch a case where the client disconnects during a call
  
  - track all talloc memory, using NULL context
modified:
  server/ctdb_control.c          
ctdb_control.c-20070426122724-j6gkpiofhbwdin63-1
  server/ctdb_daemon.c           ctdb_daemon.c-20070409200331-3el1kqgdb9m4ib0g-1
  server/ctdbd.c                 ctdbd.c-20070411085044-dqmhr6mfeexnyt4m-1
=== modified file 'server/ctdb_control.c'
--- a/server/ctdb_control.c     2008-01-14 21:42:12 +0000
+++ b/server/ctdb_control.c     2008-01-15 22:44:48 +0000
@@ -71,7 +71,7 @@
 
        case CTDB_CONTROL_STATISTICS: {
                CHECK_CONTROL_DATA_SIZE(0);
-               ctdb->statistics.memory_used = talloc_total_size(ctdb);
+               ctdb->statistics.memory_used = talloc_total_size(NULL);
                ctdb->statistics.frozen = (ctdb->freeze_mode == 
CTDB_FREEZE_FROZEN);
                ctdb->statistics.recovering = (ctdb->recovery_mode == 
CTDB_RECOVERY_ACTIVE);
                outdata->dptr = (uint8_t *)&ctdb->statistics;

=== modified file 'server/ctdb_daemon.c'
--- a/server/ctdb_daemon.c      2008-01-14 21:42:12 +0000
+++ b/server/ctdb_daemon.c      2008-01-15 22:44:48 +0000
@@ -288,9 +288,37 @@
        client->ctdb->statistics.pending_calls--;
 }
 
-
-static void daemon_request_call_from_client(struct ctdb_client *client, 
-                                           struct ctdb_req_call *c);
+struct ctdb_daemon_packet_wrap {
+       struct ctdb_context *ctdb;
+       uint32_t client_id;
+};
+
+/*
+  a wrapper to catch disconnected clients
+ */
+static void daemon_incoming_packet_wrap(void *p, struct ctdb_req_header *hdr)
+{
+       struct ctdb_client *client;
+       struct ctdb_daemon_packet_wrap *w = talloc_get_type(p, 
+                                                           struct 
ctdb_daemon_packet_wrap);
+       if (w == NULL) {
+               DEBUG(0,(__location__ " Bad packet type '%s'\n", 
talloc_get_name(p)));
+               return;
+       }
+
+       client = ctdb_reqid_find(w->ctdb, w->client_id, struct ctdb_client);
+       if (client == NULL) {
+               DEBUG(0,(__location__ " Packet for disconnected client %u\n",
+                        w->client_id));
+               talloc_free(w);
+               return;
+       }
+       talloc_free(w);
+
+       /* process it */
+       daemon_incoming_packet(client, hdr);    
+}
+
 
 /*
   this is called when the ctdb daemon received a ctdb request call
@@ -307,6 +335,7 @@
        TDB_DATA key, data;
        int ret;
        struct ctdb_context *ctdb = client->ctdb;
+       struct ctdb_daemon_packet_wrap *w;
 
        ctdb->statistics.total_calls++;
        ctdb->statistics.pending_calls++;
@@ -322,15 +351,23 @@
        key.dptr = c->data;
        key.dsize = c->keylen;
 
+       w = talloc(ctdb, struct ctdb_daemon_packet_wrap);
+       CTDB_NO_MEMORY_VOID(ctdb, w);   
+
+       w->ctdb = ctdb;
+       w->client_id = client->client_id;
+
        ret = ctdb_ltdb_lock_fetch_requeue(ctdb_db, key, &header, 
                                           (struct ctdb_req_header *)c, &data,
-                                          daemon_incoming_packet, client, 
True);
+                                          daemon_incoming_packet_wrap, w, 
True);
        if (ret == -2) {
                /* will retry later */
                ctdb->statistics.pending_calls--;
                return;
        }
 
+       talloc_free(w);
+
        if (ret != 0) {
                DEBUG(0,(__location__ " Unable to fetch record\n"));
                ctdb->statistics.pending_calls--;

=== modified file 'server/ctdbd.c'
--- a/server/ctdbd.c    2008-01-10 03:40:56 +0000
+++ b/server/ctdbd.c    2008-01-15 22:44:48 +0000
@@ -137,6 +137,8 @@
                exit(1);
        }
 
+       talloc_enable_null_tracking();
+
        ctdb_block_signal(SIGPIPE);
 
        ev = event_context_init(NULL);

Reply via email to