[dm-devel] [PATCH 19/35] multipathd: uxlsnr: data structure for stateful client connection

Benjamin Marzinski bmarzins at redhat.com
Thu Sep 16 02:19:01 UTC 2021


On Fri, Sep 10, 2021 at 01:41:04PM +0200, mwilck at suse.com wrote:
> From: Martin Wilck <mwilck at suse.com>
> 
> Currently the uxlsnr handles each client request (receive requset -
> handle request - respond) in a single loop iteration. This has
> severe disadvantages. In particular, the code may wait in poll()
> called from read_all(), or wait for the vecs lock, while other
> clients are ready to be serviced or signals to be handled.
> 
> This patch adds some fields to "struct client" which will be used
> by later patches to change this into a state machine that basically
> waits only in place, the ppoll() call in uxsock_listen().
> 
> For now, we just introduce and initialize the fields.
> 

Reviewed-by: Benjamin Marzinski <bmarzins at redhat.com>
> Signed-off-by: Martin Wilck <mwilck at suse.com>
> ---
>  multipathd/uxlsnr.c | 27 +++++++++++++++++++++++++--
>  1 file changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c
> index 98a9f71..e701a1c 100644
> --- a/multipathd/uxlsnr.c
> +++ b/multipathd/uxlsnr.c
> @@ -40,10 +40,30 @@
>  #include "main.h"
>  #include "cli.h"
>  #include "uxlsnr.h"
> +#include "strbuf.h"
> +
> +/* state of client connection */
> +enum {
> +	CLT_RECV,
> +	CLT_PARSE,
> +	CLT_WAIT_LOCK,
> +	CLT_WORK,
> +	CLT_SEND,
> +};
>  
>  struct client {
>  	struct list_head node;
> +	struct timespec expires;
> +	int state;
>  	int fd;
> +	vector cmdvec;
> +	/* NUL byte at end */
> +	char cmd[_MAX_CMD_LEN + 1];
> +	struct strbuf reply;
> +	struct handler *handler;
> +	size_t cmd_len, len;
> +	int error;
> +	bool is_root;
>  };
>  
>  /* Indices for array of poll fds */
> @@ -104,14 +124,14 @@ static void new_client(int ux_sock)
>  	if (fd == -1)
>  		return;
>  
> -	c = (struct client *)MALLOC(sizeof(*c));
> +	c = calloc(1, sizeof(*c));
>  	if (!c) {
>  		close(fd);
>  		return;
>  	}
> -	memset(c, 0, sizeof(*c));
>  	INIT_LIST_HEAD(&c->node);
>  	c->fd = fd;
> +	c->state = CLT_RECV;
>  
>  	/* put it in our linked list */
>  	pthread_mutex_lock(&client_lock);
> @@ -127,6 +147,9 @@ static void _dead_client(struct client *c)
>  	int fd = c->fd;
>  	list_del_init(&c->node);
>  	c->fd = -1;
> +	reset_strbuf(&c->reply);
> +	if (c->cmdvec)
> +		free_keys(c->cmdvec);
>  	FREE(c);
>  	close(fd);
>  }
> -- 
> 2.33.0




More information about the dm-devel mailing list