]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cfgparse: support the comma separator on parse_cpu_set
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 6 Apr 2021 14:46:15 +0000 (16:46 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 23 Apr 2021 14:06:49 +0000 (16:06 +0200)
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.

include/haproxy/cfgparse.h
src/cfgparse-global.c
src/cfgparse.c

index 8af4e47cd11f7526f76379106cbef7bbb11afdfa..2266ac6d92605a87a10eebc7c53c3192750c2984 100644 (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(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);
-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);
 const char *cfg_find_best_match(const char *word, const struct list *list, int section, const char **extra);
 
index 694cd70776c8443e248d4cd7ba0e2a33170ed600..89e3b10b0ad2177a7f3cbeb8dd58dbd0f33036ad 100644 (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);
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
index dd8a2c13cf2e0413451340985a9ca4ddf1a22d31..f37b74894c6af750e30547965ee7d6d1ad5eacdd 100644 (file)
@@ -462,26 +462,35 @@ int parse_process_number(const char *arg, unsigned long *proc, int max, int *aut
 #ifdef USE_CPU_AFFINITY
 /* 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
- * ('-'). Multiple CPU numbers or ranges may be specified. On success, it
- * returns 0. otherwise it returns 1 with an error message in <err>.
+ * ('-'). If <comma_allowed> is set, each CPU set can be a list of unique
+ * 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;
+       const char *arg;
 
        ha_cpuset_zero(cpu_set);
 
-       while (*args[cur_arg]) {
-               char        *dash;
+       arg = args[cur_arg];
+       while (*arg) {
+               const char *dash, *comma;
                unsigned int low, high;
 
                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;
                }
 
-               low = high = str2uic(args[cur_arg]);
-               if ((dash = strchr(args[cur_arg], '-')) != NULL)
+               low = high = str2uic(arg);
+
+               comma = comma_allowed ? strchr(arg, ',') : NULL;
+               dash = strchr(arg, '-');
+
+               if (dash && (!comma || dash < comma))
                        high = *(dash+1) ? str2uic(dash + 1) : ha_cpuset_size() - 1;
 
                if (high < low) {
@@ -499,7 +508,9 @@ unsigned long parse_cpu_set(const char **args, struct hap_cpuset *cpu_set, char
                while (low <= high)
                        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;
 }