]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/bus-unit-util: add helper for NUMAMask=
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 18 Jun 2025 15:32:20 +0000 (17:32 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 3 Jul 2025 17:35:33 +0000 (19:35 +0200)
src/shared/bus-unit-util.c

index ccb5c8ed81163dccbb85505f0feee00d528aa079..d3d2eb6dcf1c52926030388f183e271b97c3667e 100644 (file)
@@ -1329,6 +1329,29 @@ static int bus_append_cpu_affinity(sd_bus_message *m, const char *field, const c
         return bus_append_parse_cpu_set(m, field, eq);
 }
 
+static int bus_append_numa_mask(sd_bus_message *m, const char *field, const char *eq) {
+        _cleanup_(cpu_set_done) CPUSet nodes = {};
+        _cleanup_free_ uint8_t *array = NULL;
+        size_t allocated;
+        int r;
+
+        if (eq && streq(eq, "all")) {
+                r = numa_mask_add_all(&nodes);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to create NUMA mask representing \"all\" NUMA nodes: %m");
+        } else {
+                r = parse_cpu_set(eq, &nodes);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to parse %s value: %s", field, eq);
+        }
+
+        r = cpu_set_to_dbus(&nodes, &array, &allocated);
+        if (r < 0)
+                return log_error_errno(r, "Failed to serialize %s: %m", field);
+
+        return bus_append_byte_array(m, field, array, allocated);
+}
+
 static int bus_append_cgroup_property(sd_bus_message *m, const char *field, const char *eq) {
         if (STR_IN_SET(field, "DevicePolicy",
                               "Slice",
@@ -1654,27 +1677,8 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
         if (streq(field, "NUMAPolicy"))
                 return bus_append_mpol_from_string(m, field, eq);
 
-        if (streq(field, "NUMAMask")) {
-                _cleanup_(cpu_set_done) CPUSet nodes = {};
-                _cleanup_free_ uint8_t *array = NULL;
-                size_t allocated;
-
-                if (eq && streq(eq, "all")) {
-                        r = numa_mask_add_all(&nodes);
-                        if (r < 0)
-                                return log_error_errno(r, "Failed to create NUMA mask representing \"all\" NUMA nodes: %m");
-                } else {
-                        r = parse_cpu_set(eq, &nodes);
-                        if (r < 0)
-                                return log_error_errno(r, "Failed to parse %s value: %s", field, eq);
-                }
-
-                r = cpu_set_to_dbus(&nodes, &array, &allocated);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to serialize NUMAMask: %m");
-
-                return bus_append_byte_array(m, field, array, allocated);
-        }
+        if (streq(field, "NUMAMask"))
+                return bus_append_numa_mask(m, field, eq);
 
         if (STR_IN_SET(field, "RestrictAddressFamilies",
                               "RestrictFileSystems",