]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/load-fragment: rename config_parse_allowed_cpuset() -> config_parse_unit_cpu_set()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 21 Jun 2025 01:46:46 +0000 (10:46 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 23 Jun 2025 15:20:20 +0000 (00:20 +0900)
Then, use it in other conf parsers.
With this change, now NUMAMask= setting accepts unit specifiers.

src/core/load-fragment-gperf.gperf.in
src/core/load-fragment.c
src/core/load-fragment.h
src/core/main.c

index 9b9902a77a15763c80085a429e901445c1f3dfc0..aacc76d05342c27ded5af9e1469d92c9a6fab889 100644 (file)
@@ -30,7 +30,7 @@
 {{type}}.CPUSchedulingResetOnFork,            config_parse_bool,                                  0,                                  offsetof({{type}}, exec_context.cpu_sched_reset_on_fork)
 {{type}}.CPUAffinity,                         config_parse_exec_cpu_affinity,                     0,                                  offsetof({{type}}, exec_context)
 {{type}}.NUMAPolicy,                          config_parse_numa_policy,                           0,                                  offsetof({{type}}, exec_context.numa_policy.type)
-{{type}}.NUMAMask,                            config_parse_numa_mask,                             0,                                  offsetof({{type}}, exec_context.numa_policy)
+{{type}}.NUMAMask,                            config_parse_numa_mask,                             0,                                  offsetof({{type}}, exec_context.numa_policy.nodes)
 {{type}}.UMask,                               config_parse_mode,                                  0,                                  offsetof({{type}}, exec_context.umask)
 {{type}}.Environment,                         config_parse_environ,                               0,                                  offsetof({{type}}, exec_context.environment)
 {{type}}.EnvironmentFile,                     config_parse_unit_env_file,                         0,                                  offsetof({{type}}, exec_context.environment_files)
 
 {%- macro CGROUP_CONTEXT_CONFIG_ITEMS(type) -%}
 {{type}}.Slice,                               config_parse_unit_slice,                            0,                                  0
-{{type}}.AllowedCPUs,                         config_parse_allowed_cpuset,                        0,                                  offsetof({{type}}, cgroup_context.cpuset_cpus)
-{{type}}.StartupAllowedCPUs,                  config_parse_allowed_cpuset,                        0,                                  offsetof({{type}}, cgroup_context.startup_cpuset_cpus)
-{{type}}.AllowedMemoryNodes,                  config_parse_allowed_cpuset,                        0,                                  offsetof({{type}}, cgroup_context.cpuset_mems)
-{{type}}.StartupAllowedMemoryNodes,           config_parse_allowed_cpuset,                        0,                                  offsetof({{type}}, cgroup_context.startup_cpuset_mems)
+{{type}}.AllowedCPUs,                         config_parse_unit_cpu_set,                          0,                                  offsetof({{type}}, cgroup_context.cpuset_cpus)
+{{type}}.StartupAllowedCPUs,                  config_parse_unit_cpu_set,                          0,                                  offsetof({{type}}, cgroup_context.startup_cpuset_cpus)
+{{type}}.AllowedMemoryNodes,                  config_parse_unit_cpu_set,                          0,                                  offsetof({{type}}, cgroup_context.cpuset_mems)
+{{type}}.StartupAllowedMemoryNodes,           config_parse_unit_cpu_set,                          0,                                  offsetof({{type}}, cgroup_context.startup_cpuset_mems)
 {{type}}.CPUAccounting,                       config_parse_warn_compat,                           DISABLED_LEGACY,                    0
 {{type}}.CPUWeight,                           config_parse_cg_cpu_weight,                         0,                                  offsetof({{type}}, cgroup_context.cpu_weight)
 {{type}}.StartupCPUWeight,                    config_parse_cg_cpu_weight,                         0,                                  offsetof({{type}}, cgroup_context.startup_cpu_weight)
index fb8c786d24727595c49bb68a827c99169805fae3..ed677aa31fb163ac7c7b9e014824ab782600b571 100644 (file)
@@ -1539,35 +1539,48 @@ int config_parse_exec_cpu_sched_policy(const char *unit,
         return 0;
 }
 
-int config_parse_numa_mask(const char *unit,
-                           const char *filename,
-                           unsigned line,
-                           const char *section,
-                           unsigned section_line,
-                           const char *lvalue,
-                           int ltype,
-                           const char *rvalue,
-                           void *data,
-                           void *userdata) {
+int config_parse_numa_mask(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        CPUSet *cpu_set = ASSERT_PTR(data);
         int r;
-        NUMAPolicy *p = ASSERT_PTR(data);
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
 
         if (streq(rvalue, "all")) {
-                r = numa_mask_add_all(&p->nodes);
+                _cleanup_(cpu_set_done) CPUSet c = {};
+
+                r = numa_mask_add_all(&c);
                 if (r < 0)
                         log_syntax(unit, LOG_WARNING, filename, line, r,
                                    "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
-        } else {
-                r = parse_cpu_set_extend(rvalue, &p->nodes, true, unit, filename, line, lvalue);
+
+                cpu_set_done(cpu_set);
+                *cpu_set = TAKE_STRUCT(c);
+                return 0;
+        }
+
+        /* When parsing system.conf or user.conf, rather than unit files, userdata is NULL. */
+        if (!userdata) {
+                r = parse_cpu_set_extend(rvalue, cpu_set, true, unit, filename, line, lvalue);
                 if (r < 0)
                         log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse NUMA node mask, ignoring: %s", rvalue);
+
+                return 0;
         }
 
-        return 0;
+        return config_parse_unit_cpu_set(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata);
 }
 
 int config_parse_exec_cpu_sched_prio(const char *unit,
@@ -1824,8 +1837,6 @@ int config_parse_exec_cpu_affinity(
                 void *userdata) {
 
         ExecContext *c = ASSERT_PTR(data);
-        const Unit *u = userdata;
-        _cleanup_free_ char *k = NULL;
         int r;
 
         assert(filename);
@@ -1835,20 +1846,11 @@ int config_parse_exec_cpu_affinity(
         if (streq(rvalue, "numa")) {
                 c->cpu_affinity_from_numa = true;
                 cpu_set_done(&c->cpu_set);
-
                 return 0;
         }
 
-        r = unit_full_printf(u, rvalue, &k);
-        if (r < 0) {
-                log_syntax(unit, LOG_WARNING, filename, line, r,
-                           "Failed to resolve unit specifiers in '%s', ignoring: %m",
-                           rvalue);
-                return 0;
-        }
-
-        r = parse_cpu_set_extend(k, &c->cpu_set, true, unit, filename, line, lvalue);
-        if (r >= 0)
+        r = config_parse_unit_cpu_set(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &c->cpu_set, userdata);
+        if (r > 0)
                 c->cpu_affinity_from_numa = false;
 
         return 0;
@@ -3769,7 +3771,7 @@ int config_parse_cpu_quota(
         return 0;
 }
 
-int config_parse_allowed_cpuset(
+int config_parse_unit_cpu_set(
                 const char *unit,
                 const char *filename,
                 unsigned line,
@@ -3798,8 +3800,11 @@ int config_parse_allowed_cpuset(
                 return 0;
         }
 
-        (void) parse_cpu_set_extend(k, c, true, unit, filename, line, lvalue);
-        return 0;
+        r = parse_cpu_set_extend(k, c, true, unit, filename, line, lvalue);
+        if (r < 0)
+                return 0;
+
+        return 1;
 }
 
 int config_parse_memory_limit(
index 1d595a043bcf87f9cc367ef05ca4a769f4192642..1365174de607281e1fa820988a78b00e722a6f9b 100644 (file)
@@ -112,7 +112,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_private_users);
 CONFIG_PARSER_PROTOTYPE(config_parse_private_pids);
 CONFIG_PARSER_PROTOTYPE(config_parse_protect_control_groups);
 CONFIG_PARSER_PROTOTYPE(config_parse_cpu_quota);
-CONFIG_PARSER_PROTOTYPE(config_parse_allowed_cpuset);
+CONFIG_PARSER_PROTOTYPE(config_parse_unit_cpu_set);
 CONFIG_PARSER_PROTOTYPE(config_parse_protect_home);
 CONFIG_PARSER_PROTOTYPE(config_parse_protect_hostname);
 CONFIG_PARSER_PROTOTYPE(config_parse_protect_system);
index 22d4acfa07f57e463c5cd413cddf621aa5dd1749..5046d05b103747b58b68ae78e9a7f63bcbc5a4cb 100644 (file)
@@ -743,7 +743,7 @@ static int parse_config_file(void) {
                 { "Manager", "StatusUnitFormat",             config_parse_status_unit_format,    0,                        &arg_status_unit_format           },
                 { "Manager", "CPUAffinity",                  config_parse_cpu_affinity2,         0,                        &arg_cpu_affinity                 },
                 { "Manager", "NUMAPolicy",                   config_parse_numa_policy,           0,                        &arg_numa_policy.type             },
-                { "Manager", "NUMAMask",                     config_parse_numa_mask,             0,                        &arg_numa_policy                  },
+                { "Manager", "NUMAMask",                     config_parse_numa_mask,             0,                        &arg_numa_policy.nodes            },
                 { "Manager", "JoinControllers",              config_parse_warn_compat,           DISABLED_LEGACY,          NULL                              },
                 { "Manager", "RuntimeWatchdogSec",           config_parse_watchdog_sec,          0,                        &arg_runtime_watchdog             },
                 { "Manager", "RuntimeWatchdogPreSec",        config_parse_watchdog_sec,          0,                        &arg_pretimeout_watchdog          },