From: Zbigniew Jędrzejewski-Szmek Date: Wed, 18 Jun 2025 15:32:20 +0000 (+0200) Subject: shared/bus-unit-util: add helper for NUMAMask= X-Git-Tag: v258-rc1~183^2~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=187b248e5b43953158162267b4f4952327f6e400;p=thirdparty%2Fsystemd.git shared/bus-unit-util: add helper for NUMAMask= --- diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index ccb5c8ed811..d3d2eb6dcf1 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -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",