mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 16:37:19 +09:00
cgroup-util: drop 'controller' argument from cg_set_attribute(), cg_get_attribute() and friends
Non-null controller arguments are always ignored when running on cgroup v2. Let's drop the argument. No functional change, just refactoring.
This commit is contained in:
@@ -1623,13 +1623,13 @@ int cg_is_threaded(const char *path) {
|
||||
return strv_contains(v, "threaded") || strv_contains(v, "invalid");
|
||||
}
|
||||
|
||||
int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value) {
|
||||
int cg_set_attribute(const char *path, const char *attribute, const char *value) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
int r;
|
||||
|
||||
assert(attribute);
|
||||
|
||||
r = cg_get_path(controller, path, attribute, &p);
|
||||
r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, attribute, &p);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -1641,27 +1641,27 @@ int cg_set_attribute(const char *controller, const char *path, const char *attri
|
||||
return write_string_file(p, value, WRITE_STRING_FILE_DISABLE_BUFFER|WRITE_STRING_FILE_OPEN_NONBLOCKING);
|
||||
}
|
||||
|
||||
int cg_get_attribute(const char *controller, const char *path, const char *attribute, char **ret) {
|
||||
int cg_get_attribute(const char *path, const char *attribute, char **ret) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
int r;
|
||||
|
||||
assert(attribute);
|
||||
|
||||
r = cg_get_path(controller, path, attribute, &p);
|
||||
r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, attribute, &p);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return read_one_line_file(p, ret);
|
||||
}
|
||||
|
||||
int cg_get_attribute_as_uint64(const char *controller, const char *path, const char *attribute, uint64_t *ret) {
|
||||
int cg_get_attribute_as_uint64(const char *path, const char *attribute, uint64_t *ret) {
|
||||
_cleanup_free_ char *value = NULL;
|
||||
uint64_t v;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
|
||||
r = cg_get_attribute(controller, path, attribute, &value);
|
||||
r = cg_get_attribute(path, attribute, &value);
|
||||
if (r == -ENOENT)
|
||||
return -ENODATA;
|
||||
if (r < 0)
|
||||
@@ -1680,11 +1680,11 @@ int cg_get_attribute_as_uint64(const char *controller, const char *path, const c
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cg_get_attribute_as_bool(const char *controller, const char *path, const char *attribute) {
|
||||
int cg_get_attribute_as_bool(const char *path, const char *attribute) {
|
||||
_cleanup_free_ char *value = NULL;
|
||||
int r;
|
||||
|
||||
r = cg_get_attribute(controller, path, attribute, &value);
|
||||
r = cg_get_attribute(path, attribute, &value);
|
||||
if (r == -ENOENT)
|
||||
return -ENODATA;
|
||||
if (r < 0)
|
||||
|
||||
@@ -184,12 +184,12 @@ int cg_is_delegated_fd(int fd);
|
||||
|
||||
int cg_has_coredump_receive(const char *path);
|
||||
|
||||
int cg_set_attribute(const char *controller, const char *path, const char *attribute, const char *value);
|
||||
int cg_get_attribute(const char *controller, const char *path, const char *attribute, char **ret);
|
||||
int cg_get_keyed_attribute(const char *controller, const char *path, const char *attribute, char * const *keys, char **values);
|
||||
int cg_set_attribute(const char *path, const char *attribute, const char *value);
|
||||
int cg_get_attribute(const char *path, const char *attribute, char **ret);
|
||||
int cg_get_attribute_as_uint64(const char *path, const char *attribute, uint64_t *ret);
|
||||
int cg_get_attribute_as_bool(const char *path, const char *attribute);
|
||||
|
||||
int cg_get_attribute_as_uint64(const char *controller, const char *path, const char *attribute, uint64_t *ret);
|
||||
int cg_get_attribute_as_bool(const char *controller, const char *path, const char *attribute);
|
||||
int cg_get_keyed_attribute(const char *controller, const char *path, const char *attribute, char * const *keys, char **values);
|
||||
|
||||
int cg_get_owner(const char *path, uid_t *ret_uid);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ uint64_t physical_memory(void) {
|
||||
return mem;
|
||||
}
|
||||
if (r > 0) {
|
||||
r = cg_get_attribute("memory", root, "memory.max", &value);
|
||||
r = cg_get_attribute(root, "memory.max", &value);
|
||||
if (r == -ENOENT) /* Field does not exist on the system's top-level cgroup, hence don't
|
||||
* complain. (Note that it might exist on our own root though, if we live
|
||||
* in a cgroup namespace, hence check anyway instead of not even
|
||||
@@ -56,7 +56,7 @@ uint64_t physical_memory(void) {
|
||||
if (streq(value, "max"))
|
||||
return mem;
|
||||
} else {
|
||||
r = cg_get_attribute("memory", root, "memory.limit_in_bytes", &value);
|
||||
r = cg_get_attribute(root, "memory.limit_in_bytes", &value);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to read memory.limit_in_bytes cgroup attribute, ignoring cgroup memory limit: %m");
|
||||
return mem;
|
||||
@@ -159,7 +159,7 @@ uint64_t system_tasks_max(void) {
|
||||
/* We'll have the "pids.max" attribute on the our root cgroup only if we are in a
|
||||
* CLONE_NEWCGROUP namespace. On the top-level namespace this attribute is missing, hence
|
||||
* suppress any message about that */
|
||||
r = cg_get_attribute_as_uint64("pids", root, "pids.max", &c);
|
||||
r = cg_get_attribute_as_uint64(root, "pids.max", &c);
|
||||
if (r < 0 && r != -ENODATA)
|
||||
log_debug_errno(r, "Failed to read pids.max attribute of root cgroup, ignoring: %m");
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ static int set_attribute_and_warn(Unit *u, const char *attribute, const char *va
|
||||
if (!crt || !crt->cgroup_path)
|
||||
return -EOWNERDEAD;
|
||||
|
||||
r = cg_set_attribute(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, attribute, value);
|
||||
r = cg_set_attribute(crt->cgroup_path, attribute, value);
|
||||
if (r < 0)
|
||||
log_unit_full_errno(u, LOG_LEVEL_CGROUP_WRITE(r), r, "Failed to set '%s' attribute on '%s' to '%.*s': %m",
|
||||
attribute, empty_to_root(crt->cgroup_path), (int) strcspn(value, NEWLINE), value);
|
||||
@@ -287,7 +287,7 @@ static int unit_get_kernel_memory_limit(Unit *u, const char *file, uint64_t *ret
|
||||
if (!crt || !crt->cgroup_path)
|
||||
return -EOWNERDEAD;
|
||||
|
||||
return cg_get_attribute_as_uint64("memory", crt->cgroup_path, file, ret);
|
||||
return cg_get_attribute_as_uint64(crt->cgroup_path, file, ret);
|
||||
}
|
||||
|
||||
static int unit_compare_memory_limit(Unit *u, const char *property_name, uint64_t *ret_unit_value, uint64_t *ret_kernel_value) {
|
||||
@@ -1139,7 +1139,7 @@ static void cgroup_apply_cpu_idle(Unit *u, uint64_t weight) {
|
||||
|
||||
is_idle = weight == CGROUP_WEIGHT_IDLE;
|
||||
idle_val = one_zero(is_idle);
|
||||
r = cg_set_attribute("cpu", crt->cgroup_path, "cpu.idle", idle_val);
|
||||
r = cg_set_attribute(crt->cgroup_path, "cpu.idle", idle_val);
|
||||
if (r < 0 && (r != -ENOENT || is_idle))
|
||||
log_unit_full_errno(u, LOG_LEVEL_CGROUP_WRITE(r), r, "Failed to set '%s' attribute on '%s' to '%s': %m",
|
||||
"cpu.idle", empty_to_root(crt->cgroup_path), idle_val);
|
||||
@@ -1211,7 +1211,7 @@ static int set_bfq_weight(Unit *u, dev_t dev, uint64_t io_weight) {
|
||||
else
|
||||
xsprintf(buf, "%" PRIu64 "\n", bfq_weight);
|
||||
|
||||
r = cg_set_attribute(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, "io.bfq.weight", buf);
|
||||
r = cg_set_attribute(crt->cgroup_path, "io.bfq.weight", buf);
|
||||
if (r >= 0 && io_weight != bfq_weight)
|
||||
log_unit_debug(u, "%s=%" PRIu64 " scaled to io.bfq.weight=%" PRIu64,
|
||||
major(dev) > 0 ? "IODeviceWeight" : "IOWeight",
|
||||
@@ -1236,7 +1236,7 @@ static void cgroup_apply_io_device_weight(Unit *u, const char *dev_path, uint64_
|
||||
r1 = set_bfq_weight(u, dev, io_weight);
|
||||
|
||||
xsprintf(buf, DEVNUM_FORMAT_STR " %" PRIu64 "\n", DEVNUM_FORMAT_VAL(dev), io_weight);
|
||||
r2 = cg_set_attribute("io", crt->cgroup_path, "io.weight", buf);
|
||||
r2 = cg_set_attribute(crt->cgroup_path, "io.weight", buf);
|
||||
|
||||
/* Look at the configured device, when both fail, prefer io.weight errno. */
|
||||
r = r2 == -EOPNOTSUPP ? r1 : r2;
|
||||
@@ -3538,7 +3538,7 @@ int unit_get_memory_accounting(Unit *u, CGroupMemoryAccountingMetric metric, uin
|
||||
if (!FLAGS_SET(crt->cgroup_realized_mask, CGROUP_MASK_MEMORY))
|
||||
return -ENODATA;
|
||||
|
||||
r = cg_get_attribute_as_uint64("memory", crt->cgroup_path, attributes_table[metric], &bytes);
|
||||
r = cg_get_attribute_as_uint64(crt->cgroup_path, attributes_table[metric], &bytes);
|
||||
if (r < 0 && r != -ENODATA)
|
||||
return r;
|
||||
updated = r >= 0;
|
||||
@@ -3581,7 +3581,7 @@ int unit_get_tasks_current(Unit *u, uint64_t *ret) {
|
||||
if ((crt->cgroup_realized_mask & CGROUP_MASK_PIDS) == 0)
|
||||
return -ENODATA;
|
||||
|
||||
return cg_get_attribute_as_uint64("pids", crt->cgroup_path, "pids.current", ret);
|
||||
return cg_get_attribute_as_uint64(crt->cgroup_path, "pids.current", ret);
|
||||
}
|
||||
|
||||
static int unit_get_cpu_usage_raw(const Unit *u, const CGroupRuntime *crt, nsec_t *ret) {
|
||||
@@ -4142,7 +4142,7 @@ int unit_get_cpuset(Unit *u, CPUSet *cpus, const char *name) {
|
||||
if ((crt->cgroup_realized_mask & CGROUP_MASK_CPUSET) == 0)
|
||||
return -ENODATA;
|
||||
|
||||
r = cg_get_attribute("cpuset", crt->cgroup_path, name, &v);
|
||||
r = cg_get_attribute(crt->cgroup_path, name, &v);
|
||||
if (r == -ENOENT)
|
||||
return -ENODATA;
|
||||
if (r < 0)
|
||||
|
||||
@@ -235,7 +235,7 @@ static int recursively_get_cgroup_context(Hashmap *new_h, const char *path) {
|
||||
|
||||
subpath = mfree(subpath);
|
||||
|
||||
r = cg_get_attribute_as_bool("memory", cg_path, "memory.oom.group");
|
||||
r = cg_get_attribute_as_bool(cg_path, "memory.oom.group");
|
||||
/* The cgroup might be gone. Skip it as a candidate since we can't get information on it. */
|
||||
if (r == -ENOMEM)
|
||||
return r;
|
||||
|
||||
@@ -431,19 +431,19 @@ int oomd_cgroup_context_acquire(const char *path, OomdCGroupContext **ret) {
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Error getting memory used from procfs: %m");
|
||||
} else {
|
||||
r = cg_get_attribute_as_uint64(SYSTEMD_CGROUP_CONTROLLER, path, "memory.current", &ctx->current_memory_usage);
|
||||
r = cg_get_attribute_as_uint64(path, "memory.current", &ctx->current_memory_usage);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Error getting memory.current from %s: %m", path);
|
||||
|
||||
r = cg_get_attribute_as_uint64(SYSTEMD_CGROUP_CONTROLLER, path, "memory.min", &ctx->memory_min);
|
||||
r = cg_get_attribute_as_uint64(path, "memory.min", &ctx->memory_min);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Error getting memory.min from %s: %m", path);
|
||||
|
||||
r = cg_get_attribute_as_uint64(SYSTEMD_CGROUP_CONTROLLER, path, "memory.low", &ctx->memory_low);
|
||||
r = cg_get_attribute_as_uint64(path, "memory.low", &ctx->memory_low);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Error getting memory.low from %s: %m", path);
|
||||
|
||||
r = cg_get_attribute_as_uint64(SYSTEMD_CGROUP_CONTROLLER, path, "memory.swap.current", &ctx->swap_usage);
|
||||
r = cg_get_attribute_as_uint64(path, "memory.swap.current", &ctx->swap_usage);
|
||||
if (r == -ENODATA)
|
||||
/* The kernel can be compiled without support for memory.swap.* files,
|
||||
* or it can be disabled with boot param 'swapaccount=0' */
|
||||
|
||||
@@ -222,13 +222,13 @@ static int apply_solution_for_path(const char *path, const char *name) {
|
||||
"\tio.cost.model: %s\n",
|
||||
path, name, qos, model);
|
||||
|
||||
r = cg_set_attribute("io", NULL, "io.cost.qos", qos);
|
||||
r = cg_set_attribute(/* path = */ NULL, "io.cost.qos", qos);
|
||||
if (r < 0) {
|
||||
log_device_full_errno(device, r == -ENOENT ? LOG_DEBUG : LOG_ERR, r, "Failed to set io.cost.qos: %m");
|
||||
return r == -ENOENT ? 0 : r;
|
||||
}
|
||||
|
||||
r = cg_set_attribute("io", NULL, "io.cost.model", model);
|
||||
r = cg_set_attribute(/* path = */ NULL, "io.cost.model", model);
|
||||
if (r < 0) {
|
||||
log_device_full_errno(device, r == -ENOENT ? LOG_DEBUG : LOG_ERR, r, "Failed to set io.cost.model: %m");
|
||||
return r == -ENOENT ? 0 : r;
|
||||
|
||||
Reference in New Issue
Block a user