Non-null controller arguments are always ignored when running on cgroup v2.
Let's drop the argument.
No functional change, just refactoring.
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;
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)
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)
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);
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
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;
/* 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");
}
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);
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) {
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);
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",
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;
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;
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) {
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)
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;
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' */
"\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;