shared/bus-unit-util: add helper for NUMAMask=

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2025-07-03 19:35:33 +02:00
parent 85eb4381d3
commit 187b248e5b
+25 -21
View 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",