diff options
| author | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2009-12-02 13:41:04 +1100 |
|---|---|---|
| committer | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2009-12-02 13:41:04 +1100 |
| commit | 1c7de7a2ed0dea078367f301f5cd2467b466b7d9 (patch) | |
| tree | 9fd3b5b51e9741009d2a5d0f68856fddfb892e4a | |
| parent | bf27dc2d53b8d10d8714aff4deaa2e0902e32f68 (diff) | |
Add a double linked list to the ctdb_context to store a mapping between client pids and client structures.
Add the mapping to the list everytime we accept() a new client connection
and set it up to remove in the destructor when the client structure is freed.
(This used to be ctdb commit f75d379377f5d4abbff2576ddc5d58d91dc53bf4)
| -rw-r--r-- | ctdb/include/ctdb_private.h | 3 | ||||
| -rw-r--r-- | ctdb/server/ctdb_daemon.c | 36 |
2 files changed, 37 insertions, 2 deletions
diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 9a3c3e83bd..5155260be4 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -459,6 +459,9 @@ struct ctdb_context { struct ctdb_monitor_script_status_ctx *last_monitor_status_ctx; TALLOC_CTX *banning_ctx; + + /* mapping from pid to ctdb_client * */ + struct ctdb_client_pid_list *client_pids; }; struct ctdb_db_context { diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c index 8d85e76650..c72ef83fea 100644 --- a/ctdb/server/ctdb_daemon.c +++ b/ctdb/server/ctdb_daemon.c @@ -29,6 +29,13 @@ #include "../include/ctdb_private.h" #include <sys/socket.h> +struct ctdb_client_pid_list { + struct ctdb_client_pid_list *next, *prev; + struct ctdb_context *ctdb; + pid_t pid; + struct ctdb_client *client; +}; + static void daemon_incoming_packet(void *, struct ctdb_req_header *); static void print_exit_message(void) @@ -530,6 +537,17 @@ static void ctdb_daemon_read_cb(uint8_t *data, size_t cnt, void *args) daemon_incoming_packet(client, hdr); } + +static int ctdb_clientpid_destructor(struct ctdb_client_pid_list *client_pid) +{ + if (client_pid->ctdb->client_pids != NULL) { + DLIST_REMOVE(client_pid->ctdb->client_pids, client_pid); + } + + return 0; +} + + static void ctdb_accept_client(struct event_context *ev, struct fd_event *fde, uint16_t flags, void *private_data) { @@ -538,6 +556,7 @@ static void ctdb_accept_client(struct event_context *ev, struct fd_event *fde, int fd; struct ctdb_context *ctdb = talloc_get_type(private_data, struct ctdb_context); struct ctdb_client *client; + struct ctdb_client_pid_list *client_pid; #ifdef _AIX struct peercred_struct cr; socklen_t crl = sizeof(struct peercred_struct); @@ -571,12 +590,26 @@ static void ctdb_accept_client(struct event_context *ev, struct fd_event *fde, client->fd = fd; client->client_id = ctdb_reqid_new(ctdb, client); client->pid = cr.pid; - ctdb->statistics.num_clients++; + + client_pid = talloc(client, struct ctdb_client_pid_list); + if (client_pid == NULL) { + DEBUG(DEBUG_ERR,("Failed to allocate client pid structure\n")); + close(fd); + talloc_free(client); + return; + } + client_pid->ctdb = ctdb; + client_pid->pid = cr.pid; + client_pid->client = client; + + DLIST_ADD(ctdb->client_pids, client_pid); client->queue = ctdb_queue_setup(ctdb, client, fd, CTDB_DS_ALIGNMENT, ctdb_daemon_read_cb, client); talloc_set_destructor(client, ctdb_client_destructor); + talloc_set_destructor(client_pid, ctdb_clientpid_destructor); + ctdb->statistics.num_clients++; } @@ -1151,4 +1184,3 @@ int32_t ctdb_control_deregister_notify(struct ctdb_context *ctdb, uint32_t clien return 0; } - |
