shared/bus-unit-util: define helper for CPUAffinity=
This commit is contained in:
+15
-22
@@ -1315,6 +1315,19 @@ static int bus_append_capabilities(sd_bus_message *m, const char *field, const c
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int bus_append_cpu_affinity(sd_bus_message *m, const char *field, const char *eq) {
|
||||
int r;
|
||||
|
||||
if (streq_ptr(eq, "numa")) {
|
||||
r = sd_bus_message_append(m, "(sv)", "CPUAffinityFromNUMA", "b", true);
|
||||
if (r < 0)
|
||||
return bus_log_create_error(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
return bus_append_parse_cpu_set(m, field, eq);
|
||||
}
|
||||
|
||||
static int bus_append_cgroup_property(sd_bus_message *m, const char *field, const char *eq) {
|
||||
if (STR_IN_SET(field, "DevicePolicy",
|
||||
"Slice",
|
||||
@@ -1634,28 +1647,8 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
|
||||
"AmbientCapabilities"))
|
||||
return bus_append_capabilities(m, field, eq);
|
||||
|
||||
if (streq(field, "CPUAffinity")) {
|
||||
_cleanup_(cpu_set_done) CPUSet cpuset = {};
|
||||
_cleanup_free_ uint8_t *array = NULL;
|
||||
size_t allocated;
|
||||
|
||||
if (eq && streq(eq, "numa")) {
|
||||
r = sd_bus_message_append(m, "(sv)", "CPUAffinityFromNUMA", "b", true);
|
||||
if (r < 0)
|
||||
return bus_log_create_error(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
r = parse_cpu_set(eq, &cpuset);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse %s value: %s", field, eq);
|
||||
|
||||
r = cpu_set_to_dbus(&cpuset, &array, &allocated);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to serialize CPUAffinity: %m");
|
||||
|
||||
return bus_append_byte_array(m, field, array, allocated);
|
||||
}
|
||||
if (streq(field, "CPUAffinity"))
|
||||
return bus_append_cpu_affinity(m, field, eq);
|
||||
|
||||
if (streq(field, "NUMAPolicy")) {
|
||||
r = mpol_from_string(eq);
|
||||
|
||||
Reference in New Issue
Block a user