diff mbox series

[23/35] multipathd: uxlsnr: move client handling to separate function

Message ID 20210910114120.13665-24-mwilck@suse.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show
Series multipathd: uxlsnr overhaul | expand

Commit Message

Martin Wilck Sept. 10, 2021, 11:41 a.m. UTC
From: Martin Wilck <mwilck@suse.com>

No functional changes at this point. handle_client() will become
the state machine for handling client requests.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 multipathd/uxlsnr.c | 67 ++++++++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 35 deletions(-)

Comments

Benjamin Marzinski Sept. 16, 2021, 2:21 a.m. UTC | #1
On Fri, Sep 10, 2021 at 01:41:08PM +0200, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
> 
> No functional changes at this point. handle_client() will become
> the state machine for handling client requests.
> 
> Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
> ---
>  multipathd/uxlsnr.c | 67 ++++++++++++++++++++++-----------------------
>  1 file changed, 32 insertions(+), 35 deletions(-)
> 
> diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c
> index 147f81a..2fb23c8 100644
> --- a/multipathd/uxlsnr.c
> +++ b/multipathd/uxlsnr.c
> @@ -394,14 +394,42 @@ static int uxsock_trigger(char *str, char **reply, int *len,
>  	return r;
>  }
>  
> +static void handle_client(struct client *c, void *trigger_data)
> +{
> +	int rlen;
> +	char *inbuf, *reply;
> +
> +	if (recv_packet_from_client(c->fd, &inbuf, uxsock_timeout) != 0) {
> +		dead_client(c);
> +		return;
> +	}
> +
> +	if (!inbuf) {
> +		condlog(4, "recv_packet_from_client get null request");
> +		return;
> +	}
> +
> +	condlog(4, "cli[%d]: Got request [%s]", c->fd, inbuf);
> +	uxsock_trigger(inbuf, &reply, &rlen,
> +		       _socket_client_is_root(c->fd),
> +		       trigger_data);
> +
> +	if (reply) {
> +		if (send_packet(c->fd, reply) != 0)
> +			dead_client(c);
> +		else
> +			condlog(4, "cli[%d]: Reply [%d bytes]", c->fd, rlen);
> +		FREE(reply);
> +		reply = NULL;
> +	}
> +	FREE(inbuf);
> +}
> +
>  /*
>   * entry point
>   */
>  void *uxsock_listen(long ux_sock, void *trigger_data)
>  {
> -	int rlen;
> -	char *inbuf;
> -	char *reply;
>  	sigset_t mask;
>  	int max_pfds = MIN_POLLS + POLLFDS_BASE;
>  	/* conf->sequence_nr will be 1 when uxsock_listen is first called */
> @@ -504,8 +532,6 @@ void *uxsock_listen(long ux_sock, void *trigger_data)
>  		/* see if a client wants to speak to us */
>  		for (i = POLLFDS_BASE; i < n_pfds; i++) {
>  			if (polls[i].revents & (POLLIN|POLLHUP|POLLERR)) {
> -				struct timespec start_time;
> -
>  				c = NULL;
>  				pthread_mutex_lock(&client_lock);
>  				list_for_each_entry(tmp, &clients, node) {
> @@ -526,36 +552,7 @@ void *uxsock_listen(long ux_sock, void *trigger_data)
>  					dead_client(c);
>  					continue;
>  				}
> -				get_monotonic_time(&start_time);
> -				if (recv_packet_from_client(c->fd, &inbuf,
> -							    uxsock_timeout)
> -				    != 0) {
> -					dead_client(c);
> -					continue;
> -				}
> -				if (!inbuf) {
> -					condlog(4, "recv_packet_from_client "
> -						"get null request");
> -					continue;
> -				}
> -				condlog(4, "cli[%d]: Got request [%s]",
> -					polls[i].fd, inbuf);
> -				uxsock_trigger(inbuf, &reply, &rlen,
> -					       _socket_client_is_root(c->fd),
> -					       trigger_data);
> -				if (reply) {
> -					if (send_packet(c->fd,
> -							reply) != 0) {
> -						dead_client(c);
> -					} else {
> -						condlog(4, "cli[%d]: "
> -							"Reply [%d bytes]",
> -							polls[i].fd, rlen);
> -					}
> -					FREE(reply);
> -					reply = NULL;
> -				}
> -				FREE(inbuf);
> +				handle_client(c, trigger_data);
>  			}
>  		}
>  		/* see if we got a non-fatal signal */
> -- 
> 2.33.0

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
diff mbox series

Patch

diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c
index 147f81a..2fb23c8 100644
--- a/multipathd/uxlsnr.c
+++ b/multipathd/uxlsnr.c
@@ -394,14 +394,42 @@  static int uxsock_trigger(char *str, char **reply, int *len,
 	return r;
 }
 
+static void handle_client(struct client *c, void *trigger_data)
+{
+	int rlen;
+	char *inbuf, *reply;
+
+	if (recv_packet_from_client(c->fd, &inbuf, uxsock_timeout) != 0) {
+		dead_client(c);
+		return;
+	}
+
+	if (!inbuf) {
+		condlog(4, "recv_packet_from_client get null request");
+		return;
+	}
+
+	condlog(4, "cli[%d]: Got request [%s]", c->fd, inbuf);
+	uxsock_trigger(inbuf, &reply, &rlen,
+		       _socket_client_is_root(c->fd),
+		       trigger_data);
+
+	if (reply) {
+		if (send_packet(c->fd, reply) != 0)
+			dead_client(c);
+		else
+			condlog(4, "cli[%d]: Reply [%d bytes]", c->fd, rlen);
+		FREE(reply);
+		reply = NULL;
+	}
+	FREE(inbuf);
+}
+
 /*
  * entry point
  */
 void *uxsock_listen(long ux_sock, void *trigger_data)
 {
-	int rlen;
-	char *inbuf;
-	char *reply;
 	sigset_t mask;
 	int max_pfds = MIN_POLLS + POLLFDS_BASE;
 	/* conf->sequence_nr will be 1 when uxsock_listen is first called */
@@ -504,8 +532,6 @@  void *uxsock_listen(long ux_sock, void *trigger_data)
 		/* see if a client wants to speak to us */
 		for (i = POLLFDS_BASE; i < n_pfds; i++) {
 			if (polls[i].revents & (POLLIN|POLLHUP|POLLERR)) {
-				struct timespec start_time;
-
 				c = NULL;
 				pthread_mutex_lock(&client_lock);
 				list_for_each_entry(tmp, &clients, node) {
@@ -526,36 +552,7 @@  void *uxsock_listen(long ux_sock, void *trigger_data)
 					dead_client(c);
 					continue;
 				}
-				get_monotonic_time(&start_time);
-				if (recv_packet_from_client(c->fd, &inbuf,
-							    uxsock_timeout)
-				    != 0) {
-					dead_client(c);
-					continue;
-				}
-				if (!inbuf) {
-					condlog(4, "recv_packet_from_client "
-						"get null request");
-					continue;
-				}
-				condlog(4, "cli[%d]: Got request [%s]",
-					polls[i].fd, inbuf);
-				uxsock_trigger(inbuf, &reply, &rlen,
-					       _socket_client_is_root(c->fd),
-					       trigger_data);
-				if (reply) {
-					if (send_packet(c->fd,
-							reply) != 0) {
-						dead_client(c);
-					} else {
-						condlog(4, "cli[%d]: "
-							"Reply [%d bytes]",
-							polls[i].fd, rlen);
-					}
-					FREE(reply);
-					reply = NULL;
-				}
-				FREE(inbuf);
+				handle_client(c, trigger_data);
 			}
 		}
 		/* see if we got a non-fatal signal */