From bb7b7c6d5f99d70cd0cd9a40661243adc4d2f1af Mon Sep 17 00:00:00 2001 From: Patrick Caulfield Date: Tue, 16 Nov 2004 10:55:01 +0000 Subject: [PATCH] Tidy the socket callbacks so that all the work is done outside the main loop. --- daemons/clvmd/clvmd-cman.c | 8 +++++-- daemons/clvmd/clvmd.c | 46 +++++++++++++------------------------- daemons/clvmd/clvmd.h | 2 +- daemons/clvmd/tcp-comms.c | 4 ++++ 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/daemons/clvmd/clvmd-cman.c b/daemons/clvmd/clvmd-cman.c index ac5d70f6c..056ce9052 100644 --- a/daemons/clvmd/clvmd-cman.c +++ b/daemons/clvmd/clvmd-cman.c @@ -202,7 +202,7 @@ static void process_oob_msg(char *buf, int len, int nodeid) } } -int cluster_fd_callback(struct local_client *fd, char *buf, int len, char *csid, +int cluster_fd_callback(struct local_client *client, char *buf, int len, char *csid, struct local_client **new_client) { struct iovec iov[2]; @@ -246,7 +246,11 @@ int cluster_fd_callback(struct local_client *fd, char *buf, int len, char *csid, len = -1; errno = EAGAIN; } - memcpy(csid, &saddr.scl_nodeid, sizeof(saddr.scl_nodeid)); + else { + memcpy(csid, &saddr.scl_nodeid, sizeof(saddr.scl_nodeid)); + /* Send it back to clvmd */ + process_message(client, buf, len, csid); + } return len; } diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c index d67b97bbb..a04fcd5ce 100644 --- a/daemons/clvmd/clvmd.c +++ b/daemons/clvmd/clvmd.c @@ -485,7 +485,6 @@ static void main_loop(int local_sock, int cmd_timeout) if ((select_status = select(FD_SETSIZE, &in, NULL, NULL, &tv)) > 0) { struct local_client *lastfd = NULL; - struct clvm_header *inheader; char csid[MAX_CSID_LEN]; char buf[MAX_CLUSTER_MESSAGE]; @@ -514,9 +513,8 @@ static void main_loop(int local_sock, int cmd_timeout) type == CLUSTER_INTERNAL) goto closedown; - DEBUGLOG - ("ret == %d, errno = %d. removing client\n", - ret, errno); + DEBUGLOG("ret == %d, errno = %d. removing client\n", + ret, errno); lastfd->next = thisfd->next; free_fd = thisfd; thisfd = lastfd; @@ -531,33 +529,6 @@ static void main_loop(int local_sock, int cmd_timeout) thisfd->next = newfd; break; } - - switch (thisfd->type) { - case CLUSTER_MAIN_SOCK: - case CLUSTER_DATA_SOCK: - inheader = - (struct clvm_header *) buf; - ntoh_clvm(inheader); /* Byteswap fields */ - if (inheader->cmd == - CLVMD_CMD_REPLY) - process_reply - (inheader, ret, - csid); - else - add_to_lvmqueue(thisfd, - inheader, - ret, - csid); - break; - - /* All the work for these is done in the callback - rightly or wrongly... */ - case LOCAL_RENDEZVOUS: - case LOCAL_SOCK: - case THREAD_PIPE: - case CLUSTER_INTERNAL: - break; - } } lastfd = thisfd; } @@ -1697,6 +1668,19 @@ static int open_local_sock() return local_socket; } +void process_message(struct local_client *client, char *buf, int len, char *csid) +{ + struct clvm_header *inheader; + + inheader = (struct clvm_header *) buf; + ntoh_clvm(inheader); /* Byteswap fields */ + if (inheader->cmd == CLVMD_CMD_REPLY) + process_reply(inheader, len, csid); + else + add_to_lvmqueue(client, inheader, len, csid); +} + + static void check_all_callback(struct local_client *client, char *csid, int node_up) { diff --git a/daemons/clvmd/clvmd.h b/daemons/clvmd/clvmd.h index 50be3b588..c178df870 100644 --- a/daemons/clvmd/clvmd.h +++ b/daemons/clvmd/clvmd.h @@ -115,5 +115,5 @@ extern void cmd_client_cleanup(struct local_client *client); extern int add_client(struct local_client *new_client); extern void clvmd_cluster_init_completed(void); - +extern void process_message(struct local_client *client, char *buf, int len, char *csid); #endif diff --git a/daemons/clvmd/tcp-comms.c b/daemons/clvmd/tcp-comms.c index e0a53c0c6..d9b011ded 100644 --- a/daemons/clvmd/tcp-comms.c +++ b/daemons/clvmd/tcp-comms.c @@ -258,6 +258,10 @@ static int read_from_tcpsock(struct local_client *client, char *buf, int len, ch /* Tell cluster manager layer */ add_down_node(remcsid); } + else { + /* Send it back to clvmd */ + process_message(client, buf, len, csid); + } return status; }