diff mbox series

[17/35] multipathd: uxlsnr: use symbolic values for pollfd indices

Message ID 20210910114120.13665-18-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>

Avoid hardcoding the indices as 0, 1, 2...

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

Comments

Benjamin Marzinski Sept. 16, 2021, 2:18 a.m. UTC | #1
On Fri, Sep 10, 2021 at 01:41:02PM +0200, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
> 
> Avoid hardcoding the indices as 0, 1, 2...
> 
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
>  multipathd/uxlsnr.c | 25 +++++++++++++++----------
>  1 file changed, 15 insertions(+), 10 deletions(-)
> 
> diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c
> index 7e88538..6506109 100644
> --- a/multipathd/uxlsnr.c
> +++ b/multipathd/uxlsnr.c
> @@ -46,8 +46,13 @@ struct client {
>  	int fd;
>  };
>  
> -/* The number of fds we poll on, other than individual client connections */
> -#define POLLFDS_BASE 2
> +/* Indices for array of poll fds */
> +enum {
> +	POLLFD_UX = 0,
> +	POLLFD_NOTIFY,
> +	POLLFDS_BASE,
> +};
> +
>  #define POLLFD_CHUNK (4096 / sizeof(struct pollfd))
>  /* Minimum mumber of pollfds to reserve for clients */
>  #define MIN_POLLS (POLLFD_CHUNK - POLLFDS_BASE)
> @@ -339,8 +344,8 @@ void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, long ux_sock,
>  			}
>  		}
>  		if (num_clients < MAX_CLIENTS) {
> -			polls[0].fd = ux_sock;
> -			polls[0].events = POLLIN;
> +			polls[POLLFD_UX].fd = ux_sock;
> +			polls[POLLFD_UX].events = POLLIN;
>  		} else {
>  			/*
>  			 * New clients can't connect, num_clients won't grow
> @@ -348,15 +353,15 @@ void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, long ux_sock,
>  			 */
>  			condlog(1, "%s: max client connections reached, pausing polling",
>  				__func__);
> -			polls[0].fd = -1;
> +			polls[POLLFD_UX].fd = -1;
>  		}
>  
>  		reset_watch(notify_fd, &wds, &sequence_nr);
>  		if (notify_fd == -1 || (wds.conf_wd == -1 && wds.dir_wd == -1))
> -			polls[1].fd = -1;
> +			polls[POLLFD_NOTIFY].fd = -1;
>  		else
> -			polls[1].fd = notify_fd;
> -		polls[1].events = POLLIN;
> +			polls[POLLFD_NOTIFY].fd = notify_fd;
> +		polls[POLLFD_NOTIFY].events = POLLIN;
>  
>  		/* setup the clients */
>  		i = POLLFDS_BASE;
> @@ -454,12 +459,12 @@ void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, long ux_sock,
>  		handle_signals(true);
>  
>  		/* see if we got a new client */
> -		if (polls[0].revents & POLLIN) {
> +		if (polls[POLLFD_UX].revents & POLLIN) {
>  			new_client(ux_sock);
>  		}
>  
>  		/* handle inotify events on config files */
> -		if (polls[1].revents & POLLIN)
> +		if (polls[POLLFD_NOTIFY].revents & POLLIN)
>  			handle_inotify(notify_fd, &wds);
>  	}
>  
> -- 
> 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 7e88538..6506109 100644
--- a/multipathd/uxlsnr.c
+++ b/multipathd/uxlsnr.c
@@ -46,8 +46,13 @@  struct client {
 	int fd;
 };
 
-/* The number of fds we poll on, other than individual client connections */
-#define POLLFDS_BASE 2
+/* Indices for array of poll fds */
+enum {
+	POLLFD_UX = 0,
+	POLLFD_NOTIFY,
+	POLLFDS_BASE,
+};
+
 #define POLLFD_CHUNK (4096 / sizeof(struct pollfd))
 /* Minimum mumber of pollfds to reserve for clients */
 #define MIN_POLLS (POLLFD_CHUNK - POLLFDS_BASE)
@@ -339,8 +344,8 @@  void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, long ux_sock,
 			}
 		}
 		if (num_clients < MAX_CLIENTS) {
-			polls[0].fd = ux_sock;
-			polls[0].events = POLLIN;
+			polls[POLLFD_UX].fd = ux_sock;
+			polls[POLLFD_UX].events = POLLIN;
 		} else {
 			/*
 			 * New clients can't connect, num_clients won't grow
@@ -348,15 +353,15 @@  void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, long ux_sock,
 			 */
 			condlog(1, "%s: max client connections reached, pausing polling",
 				__func__);
-			polls[0].fd = -1;
+			polls[POLLFD_UX].fd = -1;
 		}
 
 		reset_watch(notify_fd, &wds, &sequence_nr);
 		if (notify_fd == -1 || (wds.conf_wd == -1 && wds.dir_wd == -1))
-			polls[1].fd = -1;
+			polls[POLLFD_NOTIFY].fd = -1;
 		else
-			polls[1].fd = notify_fd;
-		polls[1].events = POLLIN;
+			polls[POLLFD_NOTIFY].fd = notify_fd;
+		polls[POLLFD_NOTIFY].events = POLLIN;
 
 		/* setup the clients */
 		i = POLLFDS_BASE;
@@ -454,12 +459,12 @@  void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, long ux_sock,
 		handle_signals(true);
 
 		/* see if we got a new client */
-		if (polls[0].revents & POLLIN) {
+		if (polls[POLLFD_UX].revents & POLLIN) {
 			new_client(ux_sock);
 		}
 
 		/* handle inotify events on config files */
-		if (polls[1].revents & POLLIN)
+		if (polls[POLLFD_NOTIFY].revents & POLLIN)
 			handle_inotify(notify_fd, &wds);
 	}