MINOR: config: simplify bind_proc processing using proc_mask()

At a number of places we used to have null tests on bind_proc for
listeners and proxies. Let's simplify all these tests by always
having the proper bits reported via proc_mask().
This commit is contained in:
Willy Tarreau 2019-02-02 17:39:53 +01:00
parent 2415727a00
commit 6daac19b3f
3 changed files with 13 additions and 30 deletions

View File

@ -2286,10 +2286,7 @@ int check_config_validity()
#endif #endif
/* detect and address thread affinity inconsistencies */ /* detect and address thread affinity inconsistencies */
nbproc = 0; nbproc = my_ffsl(proc_mask(bind_conf->bind_proc)) - 1;
if (bind_conf->bind_proc)
nbproc = my_ffsl(bind_conf->bind_proc) - 1;
mask = bind_conf->bind_thread[nbproc]; mask = bind_conf->bind_thread[nbproc];
if (mask && !(mask & all_threads_mask)) { if (mask && !(mask & all_threads_mask)) {
unsigned long new_mask = 0; unsigned long new_mask = 0;
@ -2311,9 +2308,7 @@ int check_config_validity()
if (!bind_conf->bind_proc) if (!bind_conf->bind_proc)
continue; continue;
mask = all_proc_mask; mask = proc_mask(curproxy->bind_proc) & all_proc_mask;
if (curproxy->bind_proc)
mask &= curproxy->bind_proc;
/* mask cannot be null here thanks to the previous checks */ /* mask cannot be null here thanks to the previous checks */
nbproc = my_popcountl(bind_conf->bind_proc); nbproc = my_popcountl(bind_conf->bind_proc);
@ -3550,12 +3545,8 @@ int check_config_validity()
list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) { list_for_each_entry(bind_conf, &global.stats_fe->conf.bind, by_fe) {
unsigned long mask; unsigned long mask;
mask = all_proc_mask; mask = proc_mask(global.stats_fe->bind_proc) && all_proc_mask;
if (global.stats_fe->bind_proc) mask &= proc_mask(bind_conf->bind_proc);
mask &= global.stats_fe->bind_proc;
if (bind_conf->bind_proc)
mask &= bind_conf->bind_proc;
/* stop here if more than one process is used */ /* stop here if more than one process is used */
if (atleast2(mask)) if (atleast2(mask))
@ -3574,12 +3565,10 @@ int check_config_validity()
list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
unsigned long mask; unsigned long mask;
mask = bind_conf->bind_proc ? bind_conf->bind_proc : all_proc_mask; mask = proc_mask(bind_conf->bind_proc);
curproxy->bind_proc |= mask; curproxy->bind_proc |= mask;
} }
curproxy->bind_proc = proc_mask(curproxy->bind_proc);
if (!curproxy->bind_proc)
curproxy->bind_proc = all_proc_mask;
} }
if (global.stats_fe) { if (global.stats_fe) {
@ -3589,8 +3578,7 @@ int check_config_validity()
mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0; mask = bind_conf->bind_proc ? bind_conf->bind_proc : 0;
global.stats_fe->bind_proc |= mask; global.stats_fe->bind_proc |= mask;
} }
if (!global.stats_fe->bind_proc) global.stats_fe->bind_proc = proc_mask(global.stats_fe->bind_proc);
global.stats_fe->bind_proc = all_proc_mask;
} }
/* propagate bindings from frontends to backends. Don't do it if there /* propagate bindings from frontends to backends. Don't do it if there
@ -3604,11 +3592,8 @@ int check_config_validity()
} }
/* Bind each unbound backend to all processes when not specified. */ /* Bind each unbound backend to all processes when not specified. */
for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { for (curproxy = proxies_list; curproxy; curproxy = curproxy->next)
if (curproxy->bind_proc) curproxy->bind_proc = proc_mask(curproxy->bind_proc);
continue;
curproxy->bind_proc = all_proc_mask;
}
/*******************************************************/ /*******************************************************/
/* At this step, all proxies have a non-null bind_proc */ /* At this step, all proxies have a non-null bind_proc */

View File

@ -63,8 +63,7 @@ static void enable_listener(struct listener *listener)
HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock); HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
if (listener->state == LI_LISTEN) { if (listener->state == LI_LISTEN) {
if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) && if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
listener->bind_conf->bind_proc && !(proc_mask(listener->bind_conf->bind_proc) & pid_bit)) {
!(listener->bind_conf->bind_proc & pid_bit)) {
/* we don't want to enable this listener and don't /* we don't want to enable this listener and don't
* want any fd event to reach it. * want any fd event to reach it.
*/ */
@ -173,8 +172,7 @@ static int __resume_listener(struct listener *l)
HA_SPIN_LOCK(LISTENER_LOCK, &l->lock); HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) && if ((global.mode & (MODE_DAEMON | MODE_MWORKER)) &&
l->bind_conf->bind_proc && !(proc_mask(l->bind_conf->bind_proc) & pid_bit))
!(l->bind_conf->bind_proc & pid_bit))
goto end; goto end;
if (l->state == LI_ASSIGNED) { if (l->state == LI_ASSIGNED) {

View File

@ -1598,7 +1598,7 @@ static int dump_servers_state(struct stream_interface *si, struct buffer *buf)
char *srvrecord; char *srvrecord;
/* we don't want to report any state if the backend is not enabled on this process */ /* we don't want to report any state if the backend is not enabled on this process */
if (px->bind_proc && !(px->bind_proc & pid_bit)) if (!(proc_mask(px->bind_proc) & pid_bit))
return 1; return 1;
if (!appctx->ctx.cli.p1) if (!appctx->ctx.cli.p1)
@ -1719,7 +1719,7 @@ static int cli_io_handler_show_backend(struct appctx *appctx)
continue; continue;
/* we don't want to list a backend which is bound to this process */ /* we don't want to list a backend which is bound to this process */
if (curproxy->bind_proc && !(curproxy->bind_proc & pid_bit)) if (!(proc_mask(curproxy->bind_proc) & pid_bit))
continue; continue;
chunk_appendf(&trash, "%s\n", curproxy->id); chunk_appendf(&trash, "%s\n", curproxy->id);