MINOR: cfgparse: support the comma separator on parse_cpu_set

Allow to specify multiple cpu ids/ranges in parse_cpu_set separated by a
comma. This is optional and must be activated by a parameter.

The comma support is disabled for the parsing of the 'cpu-map' config
statement. However, it will be useful to parse files in sysfs when
inspecting the cpus topology for NUMA automatic process binding.
This commit is contained in:
Amaury Denoyelle 2021-04-06 16:46:15 +02:00
parent 4c9efdecf5
commit a80823543c
3 changed files with 22 additions and 11 deletions

View File

@ -114,7 +114,7 @@ int too_many_args(int maxarg, char **args, char **msg, int *err_code);
int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code); int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code);
int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code); int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code);
int parse_process_number(const char *arg, unsigned long *proc, int max, int *autoinc, char **err); int parse_process_number(const char *arg, unsigned long *proc, int max, int *autoinc, char **err);
unsigned long parse_cpu_set(const char **args, struct hap_cpuset *cpu_set, char **err); unsigned long parse_cpu_set(const char **args, struct hap_cpuset *cpu_set, int comma_allowed, char **err);
void free_email_alert(struct proxy *p); void free_email_alert(struct proxy *p);
const char *cfg_find_best_match(const char *word, const struct list *list, int section, const char **extra); const char *cfg_find_best_match(const char *word, const struct list *list, int section, const char **extra);

View File

@ -1070,7 +1070,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
} }
} }
if (parse_cpu_set((const char **)args+2, &cpus, &errmsg)) { if (parse_cpu_set((const char **)args+2, &cpus, 0, &errmsg)) {
ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
err_code |= ERR_ALERT | ERR_FATAL; err_code |= ERR_ALERT | ERR_FATAL;
goto out; goto out;

View File

@ -462,26 +462,35 @@ int parse_process_number(const char *arg, unsigned long *proc, int max, int *aut
#ifdef USE_CPU_AFFINITY #ifdef USE_CPU_AFFINITY
/* Parse cpu sets. Each CPU set is either a unique number between 0 and /* Parse cpu sets. Each CPU set is either a unique number between 0 and
* ha_cpuset_size() - 1 or a range with two such numbers delimited by a dash * ha_cpuset_size() - 1 or a range with two such numbers delimited by a dash
* ('-'). Multiple CPU numbers or ranges may be specified. On success, it * ('-'). If <comma_allowed> is set, each CPU set can be a list of unique
* returns 0. otherwise it returns 1 with an error message in <err>. * numbers or ranges separated by a comma. It is also possible to specify
* multiple cpu numbers or ranges in distinct argument in <args>. On success,
* it returns 0, otherwise it returns 1 with an error message in <err>.
*/ */
unsigned long parse_cpu_set(const char **args, struct hap_cpuset *cpu_set, char **err) unsigned long parse_cpu_set(const char **args, struct hap_cpuset *cpu_set,
int comma_allowed, char **err)
{ {
int cur_arg = 0; int cur_arg = 0;
const char *arg;
ha_cpuset_zero(cpu_set); ha_cpuset_zero(cpu_set);
while (*args[cur_arg]) { arg = args[cur_arg];
char *dash; while (*arg) {
const char *dash, *comma;
unsigned int low, high; unsigned int low, high;
if (!isdigit((unsigned char)*args[cur_arg])) { if (!isdigit((unsigned char)*args[cur_arg])) {
memprintf(err, "'%s' is not a CPU range.", args[cur_arg]); memprintf(err, "'%s' is not a CPU range.", arg);
return -1; return -1;
} }
low = high = str2uic(args[cur_arg]); low = high = str2uic(arg);
if ((dash = strchr(args[cur_arg], '-')) != NULL)
comma = comma_allowed ? strchr(arg, ',') : NULL;
dash = strchr(arg, '-');
if (dash && (!comma || dash < comma))
high = *(dash+1) ? str2uic(dash + 1) : ha_cpuset_size() - 1; high = *(dash+1) ? str2uic(dash + 1) : ha_cpuset_size() - 1;
if (high < low) { if (high < low) {
@ -499,7 +508,9 @@ unsigned long parse_cpu_set(const char **args, struct hap_cpuset *cpu_set, char
while (low <= high) while (low <= high)
ha_cpuset_set(cpu_set, low++); ha_cpuset_set(cpu_set, low++);
cur_arg++; /* if a comma is present, parse the rest of the arg, else
* skip to the next arg */
arg = comma ? comma + 1 : args[++cur_arg];
} }
return 0; return 0;
} }