From 051675ea8014908b445c28ce8b15ae1eee956c80 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 6 Apr 2025 15:27:25 +0900 Subject: [PATCH 01/16] test: replace deprecated CGroup v1 settings with v2 ones --- test/units/parent-deep.slice | 2 +- test/units/son.service | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/units/parent-deep.slice b/test/units/parent-deep.slice index 983ed65ffb3..352d01202ab 100644 --- a/test/units/parent-deep.slice +++ b/test/units/parent-deep.slice @@ -3,4 +3,4 @@ Description=Deeper Parent Slice [Slice] -MemoryLimit=3G +MemoryAccounting=yes diff --git a/test/units/son.service b/test/units/son.service index 0242509f3bd..575bfa18b95 100644 --- a/test/units/son.service +++ b/test/units/son.service @@ -6,4 +6,4 @@ Description=Son Service Slice=parent.slice Type=oneshot ExecStart=true -CPUShares=100 +CPUWeight=100 From 98d64ff5004b497a853e9058217c6eff46065fdb Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 6 Apr 2025 09:44:41 +0900 Subject: [PATCH 02/16] core: remove deprecated CGroup v1 settings --- src/core/load-fragment-gperf.gperf.in | 18 +-- src/core/load-fragment.c | 204 -------------------------- src/core/load-fragment.h | 4 - src/core/main.c | 2 +- 4 files changed, 10 insertions(+), 218 deletions(-) diff --git a/src/core/load-fragment-gperf.gperf.in b/src/core/load-fragment-gperf.gperf.in index 6307dbe83f1..9b8a9eea19f 100644 --- a/src/core/load-fragment-gperf.gperf.in +++ b/src/core/load-fragment-gperf.gperf.in @@ -204,8 +204,8 @@ {{type}}.CPUAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.cpu_accounting) {{type}}.CPUWeight, config_parse_cg_cpu_weight, 0, offsetof({{type}}, cgroup_context.cpu_weight) {{type}}.StartupCPUWeight, config_parse_cg_cpu_weight, 0, offsetof({{type}}, cgroup_context.startup_cpu_weight) -{{type}}.CPUShares, config_parse_cpu_shares, 0, offsetof({{type}}, cgroup_context.cpu_shares) -{{type}}.StartupCPUShares, config_parse_cpu_shares, 0, offsetof({{type}}, cgroup_context.startup_cpu_shares) +{{type}}.CPUShares, config_parse_warn_compat, DISABLED_LEGACY, 0 +{{type}}.StartupCPUShares, config_parse_warn_compat, DISABLED_LEGACY, 0 {{type}}.CPUQuota, config_parse_cpu_quota, 0, offsetof({{type}}, cgroup_context) {{type}}.CPUQuotaPeriodSec, config_parse_sec_def_infinity, 0, offsetof({{type}}, cgroup_context.cpu_quota_period_usec) {{type}}.MemoryAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.memory_accounting) @@ -224,7 +224,7 @@ {{type}}.MemoryZSwapMax, config_parse_memory_limit, 0, offsetof({{type}}, cgroup_context) {{type}}.StartupMemoryZSwapMax, config_parse_memory_limit, 0, offsetof({{type}}, cgroup_context) {{type}}.MemoryZSwapWriteback, config_parse_bool, 0, offsetof({{type}}, cgroup_context.memory_zswap_writeback) -{{type}}.MemoryLimit, config_parse_memory_limit, 0, offsetof({{type}}, cgroup_context) +{{type}}.MemoryLimit, config_parse_warn_compat, DISABLED_LEGACY, 0 {{type}}.DeviceAllow, config_parse_device_allow, 0, offsetof({{type}}, cgroup_context) {{type}}.DevicePolicy, config_parse_device_policy, 0, offsetof({{type}}, cgroup_context.device_policy) {{type}}.IOAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.io_accounting) @@ -236,12 +236,12 @@ {{type}}.IOReadIOPSMax, config_parse_io_limit, 0, offsetof({{type}}, cgroup_context) {{type}}.IOWriteIOPSMax, config_parse_io_limit, 0, offsetof({{type}}, cgroup_context) {{type}}.IODeviceLatencyTargetSec, config_parse_io_device_latency, 0, offsetof({{type}}, cgroup_context) -{{type}}.BlockIOAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.blockio_accounting) -{{type}}.BlockIOWeight, config_parse_blockio_weight, 0, offsetof({{type}}, cgroup_context.blockio_weight) -{{type}}.StartupBlockIOWeight, config_parse_blockio_weight, 0, offsetof({{type}}, cgroup_context.startup_blockio_weight) -{{type}}.BlockIODeviceWeight, config_parse_blockio_device_weight, 0, offsetof({{type}}, cgroup_context) -{{type}}.BlockIOReadBandwidth, config_parse_blockio_bandwidth, 0, offsetof({{type}}, cgroup_context) -{{type}}.BlockIOWriteBandwidth, config_parse_blockio_bandwidth, 0, offsetof({{type}}, cgroup_context) +{{type}}.BlockIOAccounting, config_parse_warn_compat, DISABLED_LEGACY, 0 +{{type}}.BlockIOWeight, config_parse_warn_compat, DISABLED_LEGACY, 0 +{{type}}.StartupBlockIOWeight, config_parse_warn_compat, DISABLED_LEGACY, 0 +{{type}}.BlockIODeviceWeight, config_parse_warn_compat, DISABLED_LEGACY, 0 +{{type}}.BlockIOReadBandwidth, config_parse_warn_compat, DISABLED_LEGACY, 0 +{{type}}.BlockIOWriteBandwidth, config_parse_warn_compat, DISABLED_LEGACY, 0 {{type}}.TasksAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.tasks_accounting) {{type}}.TasksMax, config_parse_tasks_max, 0, offsetof({{type}}, cgroup_context.tasks_max) {{type}}.Delegate, config_parse_delegate, 0, offsetof({{type}}, cgroup_context) diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index e09415e1d32..dbe556eaf26 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -153,38 +153,13 @@ DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy, oom_policy, OOMPolicy); DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference, managed_oom_preference, ManagedOOMPreference); DEFINE_CONFIG_PARSE_ENUM(config_parse_memory_pressure_watch, cgroup_pressure_watch, CGroupPressureWatch); DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos, ip_tos, int, -1); -DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight, cg_blkio_weight_parse, uint64_t); DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight, cg_weight_parse, uint64_t); DEFINE_CONFIG_PARSE_PTR(config_parse_cg_cpu_weight, cg_cpu_weight_parse, uint64_t); -static DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares_internal, cg_cpu_shares_parse, uint64_t); DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_propagation_flag, mount_propagation_flag_from_string, unsigned long); DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy, mpol, int, -1); DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format, status_unit_format, StatusUnitFormat); DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping, socket_timestamping_from_string_harder, SocketTimestamping); -int config_parse_cpu_shares( - const char *unit, - const char *filename, - unsigned line, - const char *section, - unsigned section_line, - const char *lvalue, - int ltype, - const char *rvalue, - void *data, - void *userdata) { - - assert(filename); - assert(lvalue); - assert(rvalue); - - log_syntax(unit, LOG_WARNING, filename, line, 0, - "Unit uses %s=; please use CPUWeight= instead. Support for %s= will be removed soon.", - lvalue, lvalue); - - return config_parse_cpu_shares_internal(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata); -} - bool contains_instance_specifier_superset(const char *s) { const char *p, *q; bool percent = false; @@ -3899,10 +3874,6 @@ int config_parse_memory_limit( else if (streq(lvalue, "StartupMemoryZSwapMax")) { c->startup_memory_zswap_max = bytes; c->startup_memory_zswap_max_set = true; - } else if (streq(lvalue, "MemoryLimit")) { - log_syntax(unit, LOG_WARNING, filename, line, 0, - "Unit uses MemoryLimit=; please use MemoryMax= instead. Support for MemoryLimit= will be removed soon."); - c->memory_limit = bytes; } else return -EINVAL; @@ -4477,177 +4448,6 @@ int config_parse_io_limit( return 0; } -int config_parse_blockio_device_weight( - const char *unit, - const char *filename, - unsigned line, - const char *section, - unsigned section_line, - const char *lvalue, - int ltype, - const char *rvalue, - void *data, - void *userdata) { - - _cleanup_free_ char *path = NULL, *resolved = NULL; - CGroupBlockIODeviceWeight *w; - CGroupContext *c = data; - const char *p = ASSERT_PTR(rvalue); - uint64_t u; - int r; - - assert(filename); - assert(lvalue); - - log_syntax(unit, LOG_WARNING, filename, line, 0, - "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.", - lvalue, lvalue); - - if (isempty(rvalue)) { - while (c->blockio_device_weights) - cgroup_context_free_blockio_device_weight(c, c->blockio_device_weights); - - return 0; - } - - r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); - if (r == -ENOMEM) - return log_oom(); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to extract device node and weight from '%s', ignoring.", rvalue); - return 0; - } - if (r == 0 || isempty(p)) { - log_syntax(unit, LOG_WARNING, filename, line, 0, - "Invalid device node or weight specified in '%s', ignoring.", rvalue); - return 0; - } - - r = unit_path_printf(userdata, path, &resolved); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to resolve unit specifiers in '%s', ignoring: %m", path); - return 0; - } - - r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); - if (r < 0) - return 0; - - r = cg_blkio_weight_parse(p, &u); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid block IO weight '%s', ignoring: %m", p); - return 0; - } - - assert(u != CGROUP_BLKIO_WEIGHT_INVALID); - - w = new0(CGroupBlockIODeviceWeight, 1); - if (!w) - return log_oom(); - - w->path = TAKE_PTR(resolved); - w->weight = u; - - LIST_APPEND(device_weights, c->blockio_device_weights, w); - return 0; -} - -int config_parse_blockio_bandwidth( - const char *unit, - const char *filename, - unsigned line, - const char *section, - unsigned section_line, - const char *lvalue, - int ltype, - const char *rvalue, - void *data, - void *userdata) { - - _cleanup_free_ char *path = NULL, *resolved = NULL; - CGroupBlockIODeviceBandwidth *b = NULL; - CGroupContext *c = data; - const char *p = ASSERT_PTR(rvalue); - uint64_t bytes; - bool read; - int r; - - assert(filename); - assert(lvalue); - - log_syntax(unit, LOG_WARNING, filename, line, 0, - "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.", - lvalue, lvalue); - - read = streq("BlockIOReadBandwidth", lvalue); - - if (isempty(rvalue)) { - LIST_FOREACH(device_bandwidths, t, c->blockio_device_bandwidths) { - t->rbps = CGROUP_LIMIT_MAX; - t->wbps = CGROUP_LIMIT_MAX; - } - return 0; - } - - r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); - if (r == -ENOMEM) - return log_oom(); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue); - return 0; - } - if (r == 0 || isempty(p)) { - log_syntax(unit, LOG_WARNING, filename, line, 0, - "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue); - return 0; - } - - r = unit_path_printf(userdata, path, &resolved); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to resolve unit specifiers in '%s', ignoring: %m", path); - return 0; - } - - r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); - if (r < 0) - return 0; - - r = parse_size(p, 1000, &bytes); - if (r < 0 || bytes <= 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid Block IO Bandwidth '%s', ignoring.", p); - return 0; - } - - LIST_FOREACH(device_bandwidths, t, c->blockio_device_bandwidths) - if (path_equal(resolved, t->path)) { - b = t; - break; - } - - if (!b) { - b = new0(CGroupBlockIODeviceBandwidth, 1); - if (!b) - return log_oom(); - - b->path = TAKE_PTR(resolved); - b->rbps = CGROUP_LIMIT_MAX; - b->wbps = CGROUP_LIMIT_MAX; - - LIST_APPEND(device_bandwidths, c->blockio_device_bandwidths, b); - } - - if (read) - b->rbps = bytes; - else - b->wbps = bytes; - - return 0; -} - int config_parse_job_mode_isolate( const char *unit, const char *filename, @@ -6372,7 +6172,6 @@ void unit_dump_config_items(FILE *f) { #endif { config_parse_namespace_flags, "NAMESPACES" }, { config_parse_restrict_filesystems, "FILESYSTEMS" }, - { config_parse_cpu_shares, "SHARES" }, { config_parse_cg_weight, "WEIGHT" }, { config_parse_cg_cpu_weight, "CPUWEIGHT" }, { config_parse_memory_limit, "LIMIT" }, @@ -6381,9 +6180,6 @@ void unit_dump_config_items(FILE *f) { { config_parse_io_limit, "LIMIT" }, { config_parse_io_device_weight, "DEVICEWEIGHT" }, { config_parse_io_device_latency, "DEVICELATENCY" }, - { config_parse_blockio_bandwidth, "BANDWIDTH" }, - { config_parse_blockio_weight, "WEIGHT" }, - { config_parse_blockio_device_weight, "DEVICEWEIGHT" }, { config_parse_long, "LONG" }, { config_parse_socket_service, "SERVICE" }, #if HAVE_SELINUX diff --git a/src/core/load-fragment.h b/src/core/load-fragment.h index 7b758df2e68..c789af578e2 100644 --- a/src/core/load-fragment.h +++ b/src/core/load-fragment.h @@ -81,7 +81,6 @@ CONFIG_PARSER_PROTOTYPE(config_parse_unset_environ); CONFIG_PARSER_PROTOTYPE(config_parse_unit_slice); CONFIG_PARSER_PROTOTYPE(config_parse_cg_weight); CONFIG_PARSER_PROTOTYPE(config_parse_cg_cpu_weight); -CONFIG_PARSER_PROTOTYPE(config_parse_cpu_shares); CONFIG_PARSER_PROTOTYPE(config_parse_memory_limit); CONFIG_PARSER_PROTOTYPE(config_parse_tasks_max); CONFIG_PARSER_PROTOTYPE(config_parse_delegate); @@ -95,9 +94,6 @@ CONFIG_PARSER_PROTOTYPE(config_parse_device_allow); CONFIG_PARSER_PROTOTYPE(config_parse_io_device_latency); CONFIG_PARSER_PROTOTYPE(config_parse_io_device_weight); CONFIG_PARSER_PROTOTYPE(config_parse_io_limit); -CONFIG_PARSER_PROTOTYPE(config_parse_blockio_weight); -CONFIG_PARSER_PROTOTYPE(config_parse_blockio_device_weight); -CONFIG_PARSER_PROTOTYPE(config_parse_blockio_bandwidth); CONFIG_PARSER_PROTOTYPE(config_parse_job_mode); CONFIG_PARSER_PROTOTYPE(config_parse_job_mode_isolate); CONFIG_PARSER_PROTOTYPE(config_parse_exec_selinux_context); diff --git a/src/core/main.c b/src/core/main.c index 3e7894ee5e5..2d7f574fec9 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -794,7 +794,7 @@ static int parse_config_file(void) { { "Manager", "DefaultCPUAccounting", config_parse_bool, 0, &arg_defaults.cpu_accounting }, { "Manager", "DefaultIOAccounting", config_parse_bool, 0, &arg_defaults.io_accounting }, { "Manager", "DefaultIPAccounting", config_parse_bool, 0, &arg_defaults.ip_accounting }, - { "Manager", "DefaultBlockIOAccounting", config_parse_bool, 0, &arg_defaults.blockio_accounting }, + { "Manager", "DefaultBlockIOAccounting", config_parse_warn_compat, DISABLED_LEGACY, NULL }, { "Manager", "DefaultMemoryAccounting", config_parse_bool, 0, &arg_defaults.memory_accounting }, { "Manager", "DefaultTasksAccounting", config_parse_bool, 0, &arg_defaults.tasks_accounting }, { "Manager", "DefaultTasksMax", config_parse_tasks_max, 0, &arg_defaults.tasks_max }, From db6986e02c811950f746f0d7d7dcdff6219594f9 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 6 Apr 2025 10:22:12 +0900 Subject: [PATCH 03/16] core: deprecate CGroup v1 DBus properties --- man/org.freedesktop.systemd1.xml | 330 ------------------------------- src/core/dbus-cgroup.c | 304 +++------------------------- src/core/dbus-manager.c | 3 +- src/shared/bus-get-properties.c | 3 + src/shared/bus-get-properties.h | 4 + 5 files changed, 41 insertions(+), 603 deletions(-) diff --git a/man/org.freedesktop.systemd1.xml b/man/org.freedesktop.systemd1.xml index a0955df9268..211cc8c2783 100644 --- a/man/org.freedesktop.systemd1.xml +++ b/man/org.freedesktop.systemd1.xml @@ -477,8 +477,6 @@ node /org/freedesktop/systemd1 { @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly b DefaultCPUAccounting = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") - readonly b DefaultBlockIOAccounting = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly b DefaultIOAccounting = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly b DefaultIPAccounting = ...; @@ -719,8 +717,6 @@ node /org/freedesktop/systemd1 { - - @@ -1167,8 +1163,6 @@ node /org/freedesktop/systemd1 { - - @@ -2906,10 +2900,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t StartupCPUWeight = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t CPUShares = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t StartupCPUShares = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUQuotaPerSecUSec = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUQuotaPeriodUSec = ...; @@ -2940,18 +2930,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly a(st) IODeviceLatencyTargetUSec = [...]; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly b BlockIOAccounting = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t BlockIOWeight = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t StartupBlockIOWeight = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIODeviceWeight = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIOReadBandwidth = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIOWriteBandwidth = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly b MemoryAccounting = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t DefaultMemoryLow = ...; @@ -2984,8 +2962,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly b MemoryZSwapWriteback = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t MemoryLimit = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly s DevicePolicy = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly a(ss) DeviceAllow = [...]; @@ -3565,10 +3541,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { - - - - @@ -3599,18 +3571,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { - - - - - - - - - - - - @@ -3643,8 +3603,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { - - @@ -4237,10 +4195,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { - - - - @@ -4271,18 +4225,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { - - - - - - - - - - - - @@ -4315,8 +4257,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { - - @@ -5113,10 +5053,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t StartupCPUWeight = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t CPUShares = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t StartupCPUShares = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUQuotaPerSecUSec = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUQuotaPeriodUSec = ...; @@ -5147,18 +5083,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly a(st) IODeviceLatencyTargetUSec = [...]; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly b BlockIOAccounting = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t BlockIOWeight = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t StartupBlockIOWeight = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIODeviceWeight = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIOReadBandwidth = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIOWriteBandwidth = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly b MemoryAccounting = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t DefaultMemoryLow = ...; @@ -5191,8 +5115,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly b MemoryZSwapWriteback = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t MemoryLimit = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly s DevicePolicy = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly a(ss) DeviceAllow = [...]; @@ -5784,10 +5706,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket { - - - - @@ -5818,18 +5736,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket { - - - - - - - - - - - - @@ -5862,8 +5768,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket { - - @@ -6428,10 +6332,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket { - - - - @@ -6462,18 +6362,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket { - - - - - - - - - - - - @@ -6506,8 +6394,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket { - - @@ -7136,10 +7022,6 @@ node /org/freedesktop/systemd1/unit/home_2emount { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t StartupCPUWeight = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t CPUShares = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t StartupCPUShares = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUQuotaPerSecUSec = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUQuotaPeriodUSec = ...; @@ -7170,18 +7052,6 @@ node /org/freedesktop/systemd1/unit/home_2emount { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly a(st) IODeviceLatencyTargetUSec = [...]; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly b BlockIOAccounting = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t BlockIOWeight = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t StartupBlockIOWeight = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIODeviceWeight = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIOReadBandwidth = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIOWriteBandwidth = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly b MemoryAccounting = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t DefaultMemoryLow = ...; @@ -7214,8 +7084,6 @@ node /org/freedesktop/systemd1/unit/home_2emount { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly b MemoryZSwapWriteback = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t MemoryLimit = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly s DevicePolicy = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly a(ss) DeviceAllow = [...]; @@ -7737,10 +7605,6 @@ node /org/freedesktop/systemd1/unit/home_2emount { - - - - @@ -7771,18 +7635,6 @@ node /org/freedesktop/systemd1/unit/home_2emount { - - - - - - - - - - - - @@ -7815,8 +7667,6 @@ node /org/freedesktop/systemd1/unit/home_2emount { - - @@ -8297,10 +8147,6 @@ node /org/freedesktop/systemd1/unit/home_2emount { - - - - @@ -8331,18 +8177,6 @@ node /org/freedesktop/systemd1/unit/home_2emount { - - - - - - - - - - - - @@ -8375,8 +8209,6 @@ node /org/freedesktop/systemd1/unit/home_2emount { - - @@ -9132,10 +8964,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t StartupCPUWeight = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t CPUShares = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t StartupCPUShares = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUQuotaPerSecUSec = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUQuotaPeriodUSec = ...; @@ -9166,18 +8994,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly a(st) IODeviceLatencyTargetUSec = [...]; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly b BlockIOAccounting = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t BlockIOWeight = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t StartupBlockIOWeight = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIODeviceWeight = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIOReadBandwidth = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIOWriteBandwidth = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly b MemoryAccounting = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t DefaultMemoryLow = ...; @@ -9210,8 +9026,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly b MemoryZSwapWriteback = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t MemoryLimit = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly s DevicePolicy = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly a(ss) DeviceAllow = [...]; @@ -9715,10 +9529,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap { - - - - @@ -9749,18 +9559,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap { - - - - - - - - - - - - @@ -9793,8 +9591,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap { - - @@ -10257,10 +10053,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap { - - - - @@ -10291,18 +10083,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap { - - - - - - - - - - - - @@ -10335,8 +10115,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap { - - @@ -10945,10 +10723,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t StartupCPUWeight = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t CPUShares = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t StartupCPUShares = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUQuotaPerSecUSec = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUQuotaPeriodUSec = ...; @@ -10979,18 +10753,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly a(st) IODeviceLatencyTargetUSec = [...]; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly b BlockIOAccounting = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t BlockIOWeight = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t StartupBlockIOWeight = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIODeviceWeight = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIOReadBandwidth = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIOWriteBandwidth = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly b MemoryAccounting = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t DefaultMemoryLow = ...; @@ -11023,8 +10785,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly b MemoryZSwapWriteback = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t MemoryLimit = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly s DevicePolicy = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly a(ss) DeviceAllow = [...]; @@ -11138,10 +10898,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice { - - - - @@ -11172,18 +10928,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice { - - - - - - - - - - - - @@ -11216,8 +10960,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice { - - @@ -11338,10 +11080,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice { - - - - @@ -11372,18 +11110,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice { - - - - - - - - - - - - @@ -11416,8 +11142,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice { - - @@ -11569,10 +11293,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t StartupCPUWeight = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t CPUShares = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t StartupCPUShares = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUQuotaPerSecUSec = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUQuotaPeriodUSec = ...; @@ -11603,18 +11323,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly a(st) IODeviceLatencyTargetUSec = [...]; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly b BlockIOAccounting = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t BlockIOWeight = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t StartupBlockIOWeight = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIODeviceWeight = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIOReadBandwidth = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly a(st) BlockIOWriteBandwidth = [...]; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly b MemoryAccounting = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t DefaultMemoryLow = ...; @@ -11647,8 +11355,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly b MemoryZSwapWriteback = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly t MemoryLimit = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly s DevicePolicy = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly a(ss) DeviceAllow = [...]; @@ -11782,10 +11488,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope { - - - - @@ -11816,18 +11518,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope { - - - - - - - - - - - - @@ -11860,8 +11550,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope { - - @@ -12012,10 +11700,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope { - - - - @@ -12046,18 +11730,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope { - - - - - - - - - - - - @@ -12090,8 +11762,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope { - - diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index bd355281e71..2be7dfaa295 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -35,6 +35,8 @@ static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_cgroup_device_policy, cgroup_de static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_managed_oom_mode, managed_oom_mode, ManagedOOMMode); static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_managed_oom_preference, managed_oom_preference, ManagedOOMPreference); +static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_blockio_ast, "a(st)", 0); + static int property_get_cgroup_mask( sd_bus *bus, const char *path, @@ -196,72 +198,6 @@ static int property_get_io_device_latency( return sd_bus_message_close_container(reply); } -static int property_get_blockio_device_weight( - sd_bus *bus, - const char *path, - const char *interface, - const char *property, - sd_bus_message *reply, - void *userdata, - sd_bus_error *error) { - - CGroupContext *c = ASSERT_PTR(userdata); - int r; - - assert(bus); - assert(reply); - - r = sd_bus_message_open_container(reply, 'a', "(st)"); - if (r < 0) - return r; - - LIST_FOREACH(device_weights, w, c->blockio_device_weights) { - r = sd_bus_message_append(reply, "(st)", w->path, w->weight); - if (r < 0) - return r; - } - - return sd_bus_message_close_container(reply); -} - -static int property_get_blockio_device_bandwidths( - sd_bus *bus, - const char *path, - const char *interface, - const char *property, - sd_bus_message *reply, - void *userdata, - sd_bus_error *error) { - - CGroupContext *c = ASSERT_PTR(userdata); - int r; - - assert(bus); - assert(reply); - - r = sd_bus_message_open_container(reply, 'a', "(st)"); - if (r < 0) - return r; - - LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) { - uint64_t v; - - if (streq(property, "BlockIOReadBandwidth")) - v = b->rbps; - else - v = b->wbps; - - if (v == CGROUP_LIMIT_MAX) - continue; - - r = sd_bus_message_append(reply, "(st)", b->path, v); - if (r < 0) - return r; - } - - return sd_bus_message_close_container(reply); -} - static int property_get_device_allow( sd_bus *bus, const char *path, @@ -450,8 +386,6 @@ const sd_bus_vtable bus_cgroup_vtable[] = { SD_BUS_PROPERTY("CPUAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, cpu_accounting), 0), SD_BUS_PROPERTY("CPUWeight", "t", NULL, offsetof(CGroupContext, cpu_weight), 0), SD_BUS_PROPERTY("StartupCPUWeight", "t", NULL, offsetof(CGroupContext, startup_cpu_weight), 0), - SD_BUS_PROPERTY("CPUShares", "t", NULL, offsetof(CGroupContext, cpu_shares), 0), - SD_BUS_PROPERTY("StartupCPUShares", "t", NULL, offsetof(CGroupContext, startup_cpu_shares), 0), SD_BUS_PROPERTY("CPUQuotaPerSecUSec", "t", bus_property_get_usec, offsetof(CGroupContext, cpu_quota_per_sec_usec), 0), SD_BUS_PROPERTY("CPUQuotaPeriodUSec", "t", bus_property_get_usec, offsetof(CGroupContext, cpu_quota_period_usec), 0), SD_BUS_PROPERTY("AllowedCPUs", "ay", property_get_cpuset, offsetof(CGroupContext, cpuset_cpus), 0), @@ -467,12 +401,6 @@ const sd_bus_vtable bus_cgroup_vtable[] = { SD_BUS_PROPERTY("IOReadIOPSMax", "a(st)", property_get_io_device_limits, 0, 0), SD_BUS_PROPERTY("IOWriteIOPSMax", "a(st)", property_get_io_device_limits, 0, 0), SD_BUS_PROPERTY("IODeviceLatencyTargetUSec", "a(st)", property_get_io_device_latency, 0, 0), - SD_BUS_PROPERTY("BlockIOAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, blockio_accounting), 0), - SD_BUS_PROPERTY("BlockIOWeight", "t", NULL, offsetof(CGroupContext, blockio_weight), 0), - SD_BUS_PROPERTY("StartupBlockIOWeight", "t", NULL, offsetof(CGroupContext, startup_blockio_weight), 0), - SD_BUS_PROPERTY("BlockIODeviceWeight", "a(st)", property_get_blockio_device_weight, 0, 0), - SD_BUS_PROPERTY("BlockIOReadBandwidth", "a(st)", property_get_blockio_device_bandwidths, 0, 0), - SD_BUS_PROPERTY("BlockIOWriteBandwidth", "a(st)", property_get_blockio_device_bandwidths, 0, 0), SD_BUS_PROPERTY("MemoryAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, memory_accounting), 0), SD_BUS_PROPERTY("DefaultMemoryLow", "t", NULL, offsetof(CGroupContext, default_memory_low), 0), SD_BUS_PROPERTY("DefaultStartupMemoryLow", "t", NULL, offsetof(CGroupContext, default_startup_memory_low), 0), @@ -489,7 +417,6 @@ const sd_bus_vtable bus_cgroup_vtable[] = { SD_BUS_PROPERTY("MemoryZSwapMax", "t", NULL, offsetof(CGroupContext, memory_zswap_max), 0), SD_BUS_PROPERTY("StartupMemoryZSwapMax", "t", NULL, offsetof(CGroupContext, startup_memory_zswap_max), 0), SD_BUS_PROPERTY("MemoryZSwapWriteback", "b", bus_property_get_bool, offsetof(CGroupContext, memory_zswap_writeback), 0), - SD_BUS_PROPERTY("MemoryLimit", "t", NULL, offsetof(CGroupContext, memory_limit), 0), SD_BUS_PROPERTY("DevicePolicy", "s", property_get_cgroup_device_policy, offsetof(CGroupContext, device_policy), 0), SD_BUS_PROPERTY("DeviceAllow", "a(ss)", property_get_device_allow, 0, 0), SD_BUS_PROPERTY("TasksAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, tasks_accounting), 0), @@ -513,6 +440,16 @@ const sd_bus_vtable bus_cgroup_vtable[] = { SD_BUS_PROPERTY("MemoryPressureThresholdUSec", "t", bus_property_get_usec, offsetof(CGroupContext, memory_pressure_threshold_usec), 0), SD_BUS_PROPERTY("NFTSet", "a(iiss)", property_get_cgroup_nft_set, 0, 0), SD_BUS_PROPERTY("CoredumpReceive", "b", bus_property_get_bool, offsetof(CGroupContext, coredump_receive), 0), + /* deprecated cgroup v1 properties */ + SD_BUS_PROPERTY("MemoryLimit", "t", bus_property_get_uint64_max, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), + SD_BUS_PROPERTY("CPUShares", "t", bus_property_get_uint64_max, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), + SD_BUS_PROPERTY("StartupCPUShares", "t", bus_property_get_uint64_max, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), + SD_BUS_PROPERTY("BlockIOAccounting", "b", bus_property_get_bool_false, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), + SD_BUS_PROPERTY("BlockIOWeight", "t", bus_property_get_uint64_max, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), + SD_BUS_PROPERTY("StartupBlockIOWeight", "t", bus_property_get_uint64_max, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), + SD_BUS_PROPERTY("BlockIODeviceWeight", "a(st)", property_get_blockio_ast, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), + SD_BUS_PROPERTY("BlockIOReadBandwidth", "a(st)", property_get_blockio_ast, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), + SD_BUS_PROPERTY("BlockIOWriteBandwidth", "a(st)", property_get_blockio_ast, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), SD_BUS_VTABLE_END }; @@ -993,9 +930,7 @@ static int bus_cgroup_set_boolean( } DISABLE_WARNING_TYPE_LIMITS; -BUS_DEFINE_SET_CGROUP_WEIGHT(cpu_shares, CGROUP_MASK_CPU, CGROUP_CPU_SHARES_IS_OK, CGROUP_CPU_SHARES_INVALID); BUS_DEFINE_SET_CGROUP_WEIGHT(io_weight, CGROUP_MASK_IO, CGROUP_WEIGHT_IS_OK, CGROUP_WEIGHT_INVALID); -BUS_DEFINE_SET_CGROUP_WEIGHT(blockio_weight, CGROUP_MASK_BLKIO, CGROUP_BLKIO_WEIGHT_IS_OK, CGROUP_BLKIO_WEIGHT_INVALID); BUS_DEFINE_SET_CGROUP_LIMIT(memory, CGROUP_MASK_MEMORY, physical_memory_scale, 1); BUS_DEFINE_SET_CGROUP_LIMIT(memory_protection, CGROUP_MASK_MEMORY, physical_memory_scale, 0); BUS_DEFINE_SET_CGROUP_LIMIT(swap, CGROUP_MASK_MEMORY, physical_memory_scale, 0); @@ -1127,12 +1062,6 @@ int bus_cgroup_set_property( if (streq(name, "StartupCPUWeight")) return bus_cgroup_set_cpu_weight(u, name, &c->startup_cpu_weight, message, flags, error); - if (streq(name, "CPUShares")) - return bus_cgroup_set_cpu_shares(u, name, &c->cpu_shares, message, flags, error); - - if (streq(name, "StartupCPUShares")) - return bus_cgroup_set_cpu_shares(u, name, &c->startup_cpu_shares, message, flags, error); - if (streq(name, "IOAccounting")) return bus_cgroup_set_boolean(u, name, &c->io_accounting, CGROUP_MASK_IO, message, flags, error); @@ -1142,15 +1071,6 @@ int bus_cgroup_set_property( if (streq(name, "StartupIOWeight")) return bus_cgroup_set_io_weight(u, name, &c->startup_io_weight, message, flags, error); - if (streq(name, "BlockIOAccounting")) - return bus_cgroup_set_boolean(u, name, &c->blockio_accounting, CGROUP_MASK_BLKIO, message, flags, error); - - if (streq(name, "BlockIOWeight")) - return bus_cgroup_set_blockio_weight(u, name, &c->blockio_weight, message, flags, error); - - if (streq(name, "StartupBlockIOWeight")) - return bus_cgroup_set_blockio_weight(u, name, &c->startup_blockio_weight, message, flags, error); - if (streq(name, "MemoryAccounting")) return bus_cgroup_set_boolean(u, name, &c->memory_accounting, CGROUP_MASK_MEMORY, message, flags, error); @@ -1236,9 +1156,6 @@ int bus_cgroup_set_property( return r; } - if (streq(name, "MemoryLimit")) - return bus_cgroup_set_memory(u, name, &c->memory_limit, message, flags, error); - if (streq(name, "MemoryMinScale")) { r = bus_cgroup_set_memory_protection_scale(u, name, &c->memory_min, message, flags, error); if (r > 0) @@ -1279,9 +1196,6 @@ int bus_cgroup_set_property( if (streq(name, "MemoryMaxScale")) return bus_cgroup_set_memory_scale(u, name, &c->memory_max, message, flags, error); - if (streq(name, "MemoryLimitScale")) - return bus_cgroup_set_memory_scale(u, name, &c->memory_limit, message, flags, error); - if (streq(name, "MemoryZSwapWriteback")) return bus_cgroup_set_boolean(u, name, &c->memory_zswap_writeback, CGROUP_MASK_MEMORY, message, flags, error); @@ -1622,180 +1536,6 @@ int bus_cgroup_set_property( return 1; - } else if (STR_IN_SET(name, "BlockIOReadBandwidth", "BlockIOWriteBandwidth")) { - const char *path; - unsigned n = 0; - uint64_t u64; - bool read; - - read = streq(name, "BlockIOReadBandwidth"); - - r = sd_bus_message_enter_container(message, 'a', "(st)"); - if (r < 0) - return r; - - while ((r = sd_bus_message_read(message, "(st)", &path, &u64)) > 0) { - - if (!path_is_normalized(path)) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path '%s' specified in %s= is not normalized.", name, path); - - if (!UNIT_WRITE_FLAGS_NOOP(flags)) { - CGroupBlockIODeviceBandwidth *a = NULL; - - LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) - if (path_equal(path, b->path)) { - a = b; - break; - } - - if (!a) { - a = new0(CGroupBlockIODeviceBandwidth, 1); - if (!a) - return -ENOMEM; - - a->rbps = CGROUP_LIMIT_MAX; - a->wbps = CGROUP_LIMIT_MAX; - a->path = strdup(path); - if (!a->path) { - free(a); - return -ENOMEM; - } - - LIST_APPEND(device_bandwidths, c->blockio_device_bandwidths, a); - } - - if (read) - a->rbps = u64; - else - a->wbps = u64; - } - - n++; - } - if (r < 0) - return r; - - r = sd_bus_message_exit_container(message); - if (r < 0) - return r; - - if (!UNIT_WRITE_FLAGS_NOOP(flags)) { - _cleanup_(memstream_done) MemStream m = {}; - _cleanup_free_ char *buf = NULL; - FILE *f; - - if (n == 0) - LIST_FOREACH(device_bandwidths, a, c->blockio_device_bandwidths) { - if (read) - a->rbps = CGROUP_LIMIT_MAX; - else - a->wbps = CGROUP_LIMIT_MAX; - } - - unit_invalidate_cgroup(u, CGROUP_MASK_BLKIO); - - f = memstream_init(&m); - if (!f) - return -ENOMEM; - - if (read) { - fputs("BlockIOReadBandwidth=\n", f); - LIST_FOREACH(device_bandwidths, a, c->blockio_device_bandwidths) - if (a->rbps != CGROUP_LIMIT_MAX) - fprintf(f, "BlockIOReadBandwidth=%s %" PRIu64 "\n", a->path, a->rbps); - } else { - fputs("BlockIOWriteBandwidth=\n", f); - LIST_FOREACH(device_bandwidths, a, c->blockio_device_bandwidths) - if (a->wbps != CGROUP_LIMIT_MAX) - fprintf(f, "BlockIOWriteBandwidth=%s %" PRIu64 "\n", a->path, a->wbps); - } - - r = memstream_finalize(&m, &buf, NULL); - if (r < 0) - return r; - - unit_write_setting(u, flags, name, buf); - } - - return 1; - - } else if (streq(name, "BlockIODeviceWeight")) { - const char *path; - uint64_t weight; - unsigned n = 0; - - r = sd_bus_message_enter_container(message, 'a', "(st)"); - if (r < 0) - return r; - - while ((r = sd_bus_message_read(message, "(st)", &path, &weight)) > 0) { - - if (!path_is_normalized(path)) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path '%s' specified in %s= is not normalized.", name, path); - - if (!CGROUP_BLKIO_WEIGHT_IS_OK(weight) || weight == CGROUP_BLKIO_WEIGHT_INVALID) - return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "BlockIODeviceWeight= out of range"); - - if (!UNIT_WRITE_FLAGS_NOOP(flags)) { - CGroupBlockIODeviceWeight *a = NULL; - - LIST_FOREACH(device_weights, b, c->blockio_device_weights) - if (path_equal(b->path, path)) { - a = b; - break; - } - - if (!a) { - a = new0(CGroupBlockIODeviceWeight, 1); - if (!a) - return -ENOMEM; - - a->path = strdup(path); - if (!a->path) { - free(a); - return -ENOMEM; - } - LIST_APPEND(device_weights, c->blockio_device_weights, a); - } - - a->weight = weight; - } - - n++; - } - - r = sd_bus_message_exit_container(message); - if (r < 0) - return r; - - if (!UNIT_WRITE_FLAGS_NOOP(flags)) { - _cleanup_(memstream_done) MemStream m = {}; - _cleanup_free_ char *buf = NULL; - FILE *f; - - if (n == 0) - while (c->blockio_device_weights) - cgroup_context_free_blockio_device_weight(c, c->blockio_device_weights); - - unit_invalidate_cgroup(u, CGROUP_MASK_BLKIO); - - f = memstream_init(&m); - if (!f) - return -ENOMEM; - - fputs("BlockIODeviceWeight=\n", f); - LIST_FOREACH(device_weights, a, c->blockio_device_weights) - fprintf(f, "BlockIODeviceWeight=%s %" PRIu64 "\n", a->path, a->weight); - - r = memstream_finalize(&m, &buf, NULL); - if (r < 0) - return r; - - unit_write_setting(u, flags, name, buf); - } - - return 1; - } else if (streq(name, "DevicePolicy")) { const char *policy; CGroupDevicePolicy p; @@ -2319,6 +2059,26 @@ int bus_cgroup_set_property( return 1; } + /* deprecated CGroup v1 properties */ + if (STR_IN_SET(name, + "MemoryLimit", + "MemoryLimitScale", + "CPUShares", + "StartupCPUShares", + "BlockIOAccounting", + "BlockIOWeight", + "StartupBlockIOWeight", + "BlockIODeviceWeight", + "BlockIOReadBandwidth", + "BlockIOWriteBandwidth")) { + + r = sd_bus_message_skip(message, NULL); + if (r < 0) + return r; + + return 1; + } + /* must be last */ if (streq(name, "DisableControllers") || (u->transient && u->load_state == UNIT_STUB)) return bus_cgroup_set_transient_property(u, c, name, message, flags, error); diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 8addce3d102..bf86e799096 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -3057,7 +3057,6 @@ const sd_bus_vtable bus_manager_vtable[] = { SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec, offsetof(Manager, defaults.start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned, offsetof(Manager, defaults.start_limit.burst), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.cpu_accounting), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.blockio_accounting), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("DefaultIOAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.io_accounting), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("DefaultIPAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.ip_accounting), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.memory_accounting), SD_BUS_VTABLE_PROPERTY_CONST), @@ -3102,6 +3101,8 @@ const sd_bus_vtable bus_manager_vtable[] = { SD_BUS_PROPERTY("DefaultOOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("CtrlAltDelBurstAction", "s", bus_property_get_emergency_action, offsetof(Manager, cad_burst_action), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("SoftRebootsCount", "u", bus_property_get_unsigned, offsetof(Manager, soft_reboots_count), SD_BUS_VTABLE_PROPERTY_CONST), + /* deprecated cgroup v1 property */ + SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool_false, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), SD_BUS_METHOD_WITH_ARGS("GetUnit", SD_BUS_ARGS("s", name), diff --git a/src/shared/bus-get-properties.c b/src/shared/bus-get-properties.c index bf267a23a55..696671a916e 100644 --- a/src/shared/bus-get-properties.c +++ b/src/shared/bus-get-properties.c @@ -6,6 +6,9 @@ #include "stdio-util.h" #include "string-util.h" +BUS_DEFINE_PROPERTY_GET_GLOBAL(bus_property_get_bool_false, "b", 0); +BUS_DEFINE_PROPERTY_GET_GLOBAL(bus_property_get_uint64_max, "t", UINT64_MAX); + int bus_property_get_bool( sd_bus *bus, const char *path, diff --git a/src/shared/bus-get-properties.h b/src/shared/bus-get-properties.h index 9ddf5454de6..73e85cd2c86 100644 --- a/src/shared/bus-get-properties.h +++ b/src/shared/bus-get-properties.h @@ -5,6 +5,10 @@ #include "macro.h" +/* For deprecated properties. */ +int bus_property_get_bool_false(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error); +int bus_property_get_uint64_max(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error); + int bus_property_get_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error); int bus_property_set_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, void *userdata, sd_bus_error *error); int bus_property_get_tristate(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error); From 5da476ac7728b91ad3a49c1b126b3559b4fbeed8 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 6 Apr 2025 11:08:10 +0900 Subject: [PATCH 04/16] bus-unit-util: refuse setting CGroup v1 properties through DBus --- src/shared/bus-unit-util.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 1e04a051a6d..c0572aff150 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -126,8 +126,6 @@ DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, ioprio_parse_priority); DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, parse_nice); DEFINE_BUS_APPEND_PARSE_PTR("i", int32_t, int, safe_atoi); DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, nsec_t, parse_nsec); -DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, uint64_t, cg_blkio_weight_parse); -DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, uint64_t, cg_cpu_shares_parse); DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, uint64_t, cg_weight_parse); DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, uint64_t, cg_cpu_weight_parse); DEFINE_BUS_APPEND_PARSE_PTR("t", uint64_t, unsigned long, mount_propagation_flag_from_string); @@ -572,7 +570,6 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons "MemoryAccounting", "MemoryZSwapWriteback", "IOAccounting", - "BlockIOAccounting", "TasksAccounting", "IPAccounting", "CoredumpReceive")) @@ -586,10 +583,6 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons "StartupIOWeight")) return bus_append_cg_weight_parse(m, field, eq); - if (STR_IN_SET(field, "CPUShares", - "StartupCPUShares")) - return bus_append_cg_cpu_shares_parse(m, field, eq); - if (STR_IN_SET(field, "AllowedCPUs", "StartupAllowedCPUs", "AllowedMemoryNodes", @@ -609,10 +602,6 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons return bus_append_byte_array(m, field, array, allocated); } - if (STR_IN_SET(field, "BlockIOWeight", - "StartupBlockIOWeight")) - return bus_append_cg_blkio_weight_parse(m, field, eq); - if (streq(field, "DisableControllers")) return bus_append_strv(m, "DisableControllers", eq, /* separator= */ NULL, EXTRACT_UNQUOTE); @@ -636,7 +625,6 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons "MemoryMax", "MemorySwapMax", "MemoryZSwapMax", - "MemoryLimit", "TasksMax")) { if (streq(eq, "infinity")) { @@ -735,9 +723,7 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons return 1; } - if (cgroup_io_limit_type_from_string(field) >= 0 || - STR_IN_SET(field, "BlockIOReadBandwidth", - "BlockIOWriteBandwidth")) { + if (cgroup_io_limit_type_from_string(field) >= 0) { if (isempty(eq)) r = sd_bus_message_append(m, "(sv)", field, "a(st)", 0); @@ -771,8 +757,7 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons return 1; } - if (STR_IN_SET(field, "IODeviceWeight", - "BlockIODeviceWeight")) { + if (streq(field, "IODeviceWeight")) { if (isempty(eq)) r = sd_bus_message_append(m, "(sv)", field, "a(st)", 0); else { From 3e316a6699540f4a31e0ebfaef206b8def9dfaaf Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 6 Apr 2025 10:02:19 +0900 Subject: [PATCH 05/16] core/cgroup: remove CGroup v1 settings in dump message --- src/core/cgroup.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index c55813d662d..120c7a0e06e 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -855,14 +855,11 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { fprintf(f, "%sCPUAccounting: %s\n" "%sIOAccounting: %s\n" - "%sBlockIOAccounting: %s\n" "%sMemoryAccounting: %s\n" "%sTasksAccounting: %s\n" "%sIPAccounting: %s\n" "%sCPUWeight: %" PRIu64 "\n" "%sStartupCPUWeight: %" PRIu64 "\n" - "%sCPUShares: %" PRIu64 "\n" - "%sStartupCPUShares: %" PRIu64 "\n" "%sCPUQuotaPerSecSec: %s\n" "%sCPUQuotaPeriodSec: %s\n" "%sAllowedCPUs: %s\n" @@ -871,8 +868,6 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { "%sStartupAllowedMemoryNodes: %s\n" "%sIOWeight: %" PRIu64 "\n" "%sStartupIOWeight: %" PRIu64 "\n" - "%sBlockIOWeight: %" PRIu64 "\n" - "%sStartupBlockIOWeight: %" PRIu64 "\n" "%sDefaultMemoryMin: %" PRIu64 "\n" "%sDefaultMemoryLow: %" PRIu64 "\n" "%sMemoryMin: %" PRIu64 "%s\n" @@ -887,7 +882,6 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { "%sMemoryZSwapMax: %" PRIu64 "%s\n" "%sStartupMemoryZSwapMax: %" PRIu64 "%s\n" "%sMemoryZSwapWriteback: %s\n" - "%sMemoryLimit: %" PRIu64 "\n" "%sTasksMax: %" PRIu64 "\n" "%sDevicePolicy: %s\n" "%sDisableControllers: %s\n" @@ -900,14 +894,11 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { "%sCoredumpReceive: %s\n", prefix, yes_no(c->cpu_accounting), prefix, yes_no(c->io_accounting), - prefix, yes_no(c->blockio_accounting), prefix, yes_no(c->memory_accounting), prefix, yes_no(c->tasks_accounting), prefix, yes_no(c->ip_accounting), prefix, c->cpu_weight, prefix, c->startup_cpu_weight, - prefix, c->cpu_shares, - prefix, c->startup_cpu_shares, prefix, FORMAT_TIMESPAN(c->cpu_quota_per_sec_usec, 1), prefix, FORMAT_TIMESPAN(c->cpu_quota_period_usec, 1), prefix, strempty(cpuset_cpus), @@ -916,8 +907,6 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { prefix, strempty(startup_cpuset_mems), prefix, c->io_weight, prefix, c->startup_io_weight, - prefix, c->blockio_weight, - prefix, c->startup_blockio_weight, prefix, c->default_memory_min, prefix, c->default_memory_low, prefix, c->memory_min, format_cgroup_memory_limit_comparison(u, "MemoryMin", cda, sizeof(cda)), @@ -932,7 +921,6 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { prefix, c->memory_zswap_max, format_cgroup_memory_limit_comparison(u, "MemoryZSwapMax", cdj, sizeof(cdj)), prefix, c->startup_memory_zswap_max, format_cgroup_memory_limit_comparison(u, "StartupMemoryZSwapMax", cdk, sizeof(cdk)), prefix, yes_no(c->memory_zswap_writeback), - prefix, c->memory_limit, prefix, cgroup_tasks_max_resolve(&c->tasks_max), prefix, cgroup_device_policy_to_string(c->device_policy), prefix, strempty(disable_controllers_str), @@ -988,28 +976,6 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { il->path, FORMAT_BYTES(il->limits[type])); - LIST_FOREACH(device_weights, w, c->blockio_device_weights) - fprintf(f, - "%sBlockIODeviceWeight: %s %" PRIu64, - prefix, - w->path, - w->weight); - - LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) { - if (b->rbps != CGROUP_LIMIT_MAX) - fprintf(f, - "%sBlockIOReadBandwidth: %s %s\n", - prefix, - b->path, - FORMAT_BYTES(b->rbps)); - if (b->wbps != CGROUP_LIMIT_MAX) - fprintf(f, - "%sBlockIOWriteBandwidth: %s %s\n", - prefix, - b->path, - FORMAT_BYTES(b->wbps)); - } - SET_FOREACH(iaai, c->ip_address_allow) fprintf(f, "%sIPAddressAllow: %s\n", prefix, IN_ADDR_PREFIX_TO_STRING(iaai->family, &iaai->address, iaai->prefixlen)); From a7b06f6c30885d5b401b0d87574ca0983eb9f04b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 6 Apr 2025 16:53:19 +0900 Subject: [PATCH 06/16] core/cgroup: remove unused legacy parameters in CGroupContext --- src/core/cgroup.c | 273 ++--------------------------------- src/core/cgroup.h | 31 ---- src/core/execute-serialize.c | 165 --------------------- src/core/unit.c | 1 - 4 files changed, 14 insertions(+), 456 deletions(-) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 120c7a0e06e..bc4378bca4b 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -92,9 +92,7 @@ bool unit_has_startup_cgroup_constraints(Unit *u) { if (!c) return false; - return c->startup_cpu_shares != CGROUP_CPU_SHARES_INVALID || - c->startup_io_weight != CGROUP_WEIGHT_INVALID || - c->startup_blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID || + return c->startup_io_weight != CGROUP_WEIGHT_INVALID || c->startup_cpuset_cpus.set || c->startup_cpuset_mems.set || c->startup_memory_high_set || @@ -134,23 +132,6 @@ static int set_attribute_and_warn(Unit *u, const char *controller, const char *a return r; } -static void cgroup_compat_warn(void) { - static bool cgroup_compat_warned = false; - - if (cgroup_compat_warned) - return; - - log_warning("cgroup compatibility translation between legacy and unified hierarchy settings activated. " - "See cgroup-compat debug messages for details."); - - cgroup_compat_warned = true; -} - -#define log_cgroup_compat(unit, fmt, ...) do { \ - cgroup_compat_warn(); \ - log_unit_debug(unit, "cgroup-compat: " fmt, ##__VA_ARGS__); \ - } while (false) - void cgroup_context_init(CGroupContext *c) { assert(c); @@ -169,9 +150,6 @@ void cgroup_context_init(CGroupContext *c) { .cpu_quota_per_sec_usec = USEC_INFINITY, .cpu_quota_period_usec = USEC_INFINITY, - .cpu_shares = CGROUP_CPU_SHARES_INVALID, - .startup_cpu_shares = CGROUP_CPU_SHARES_INVALID, - .memory_high = CGROUP_LIMIT_MAX, .startup_memory_high = CGROUP_LIMIT_MAX, .memory_max = CGROUP_LIMIT_MAX, @@ -181,16 +159,11 @@ void cgroup_context_init(CGroupContext *c) { .memory_zswap_max = CGROUP_LIMIT_MAX, .startup_memory_zswap_max = CGROUP_LIMIT_MAX, - .memory_limit = CGROUP_LIMIT_MAX, - .memory_zswap_writeback = true, .io_weight = CGROUP_WEIGHT_INVALID, .startup_io_weight = CGROUP_WEIGHT_INVALID, - .blockio_weight = CGROUP_BLKIO_WEIGHT_INVALID, - .startup_blockio_weight = CGROUP_BLKIO_WEIGHT_INVALID, - .tasks_max = CGROUP_TASKS_MAX_UNSET, .moom_swap = MANAGED_OOM_AUTO, @@ -268,46 +241,6 @@ int cgroup_context_add_io_device_latency_dup(CGroupContext *c, const CGroupIODev return 0; } -int cgroup_context_add_block_io_device_weight_dup(CGroupContext *c, const CGroupBlockIODeviceWeight *w) { - _cleanup_free_ CGroupBlockIODeviceWeight *n = NULL; - - assert(c); - assert(w); - - n = new(CGroupBlockIODeviceWeight, 1); - if (!n) - return -ENOMEM; - - *n = (CGroupBlockIODeviceWeight) { - .path = strdup(w->path), - .weight = w->weight, - }; - if (!n->path) - return -ENOMEM; - - LIST_PREPEND(device_weights, c->blockio_device_weights, TAKE_PTR(n)); - return 0; -} - -int cgroup_context_add_block_io_device_bandwidth_dup(CGroupContext *c, const CGroupBlockIODeviceBandwidth *b) { - _cleanup_free_ CGroupBlockIODeviceBandwidth *n = NULL; - - assert(c); - assert(b); - - n = new(CGroupBlockIODeviceBandwidth, 1); - if (!n) - return -ENOMEM; - - *n = (CGroupBlockIODeviceBandwidth) { - .rbps = b->rbps, - .wbps = b->wbps, - }; - - LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, TAKE_PTR(n)); - return 0; -} - int cgroup_context_add_device_allow_dup(CGroupContext *c, const CGroupDeviceAllow *a) { _cleanup_free_ CGroupDeviceAllow *n = NULL; @@ -368,7 +301,6 @@ int cgroup_context_copy(CGroupContext *dst, const CGroupContext *src) { dst->cpu_accounting = src->cpu_accounting; dst->io_accounting = src->io_accounting; - dst->blockio_accounting = src->blockio_accounting; dst->memory_accounting = src->memory_accounting; dst->tasks_accounting = src->tasks_accounting; dst->ip_accounting = src->ip_accounting; @@ -473,26 +405,6 @@ int cgroup_context_copy(CGroupContext *dst, const CGroupContext *src) { } dst->restrict_network_interfaces_is_allow_list = src->restrict_network_interfaces_is_allow_list; - dst->cpu_shares = src->cpu_shares; - dst->startup_cpu_shares = src->startup_cpu_shares; - - dst->blockio_weight = src->blockio_weight; - dst->startup_blockio_weight = src->startup_blockio_weight; - - LIST_FOREACH_BACKWARDS(device_weights, l, LIST_FIND_TAIL(device_weights, src->blockio_device_weights)) { - r = cgroup_context_add_block_io_device_weight_dup(dst, l); - if (r < 0) - return r; - } - - LIST_FOREACH_BACKWARDS(device_bandwidths, l, LIST_FIND_TAIL(device_bandwidths, src->blockio_device_bandwidths)) { - r = cgroup_context_add_block_io_device_bandwidth_dup(dst, l); - if (r < 0) - return r; - } - - dst->memory_limit = src->memory_limit; - dst->device_policy = src->device_policy; LIST_FOREACH_BACKWARDS(device_allow, l, LIST_FIND_TAIL(device_allow, src->device_allow)) { r = cgroup_context_add_device_allow_dup(dst, l); @@ -554,24 +466,6 @@ void cgroup_context_free_io_device_limit(CGroupContext *c, CGroupIODeviceLimit * free(l); } -void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w) { - assert(c); - assert(w); - - LIST_REMOVE(device_weights, c->blockio_device_weights, w); - free(w->path); - free(w); -} - -void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b) { - assert(c); - assert(b); - - LIST_REMOVE(device_bandwidths, c->blockio_device_bandwidths, b); - free(b->path); - free(b); -} - void cgroup_context_remove_bpf_foreign_program(CGroupContext *c, CGroupBPFForeignProgram *p) { assert(c); assert(p); @@ -599,12 +493,6 @@ void cgroup_context_done(CGroupContext *c) { while (c->io_device_limits) cgroup_context_free_io_device_limit(c, c->io_device_limits); - while (c->blockio_device_weights) - cgroup_context_free_blockio_device_weight(c, c->blockio_device_weights); - - while (c->blockio_device_bandwidths) - cgroup_context_free_blockio_device_bandwidth(c, c->blockio_device_bandwidths); - while (c->device_allow) cgroup_context_free_device_allow(c, c->device_allow); @@ -1407,11 +1295,6 @@ static bool cgroup_context_has_cpu_weight(CGroupContext *c) { c->startup_cpu_weight != CGROUP_WEIGHT_INVALID; } -static bool cgroup_context_has_cpu_shares(CGroupContext *c) { - return c->cpu_shares != CGROUP_CPU_SHARES_INVALID || - c->startup_cpu_shares != CGROUP_CPU_SHARES_INVALID; -} - static bool cgroup_context_has_allowed_cpus(CGroupContext *c) { return c->cpuset_cpus.set || c->startup_cpuset_cpus.set; } @@ -1432,16 +1315,6 @@ uint64_t cgroup_context_cpu_weight(CGroupContext *c, ManagerState state) { return CGROUP_WEIGHT_DEFAULT; } -static uint64_t cgroup_context_cpu_shares(CGroupContext *c, ManagerState state) { - if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) && - c->startup_cpu_shares != CGROUP_CPU_SHARES_INVALID) - return c->startup_cpu_shares; - else if (c->cpu_shares != CGROUP_CPU_SHARES_INVALID) - return c->cpu_shares; - else - return CGROUP_CPU_SHARES_DEFAULT; -} - static CPUSet *cgroup_context_allowed_cpus(CGroupContext *c, ManagerState state) { if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) && c->startup_cpuset_cpus.set) @@ -1561,11 +1434,6 @@ static void cgroup_apply_legacy_cpu_quota(Unit *u, usec_t quota, usec_t period) (void) set_attribute_and_warn(u, "cpu", "cpu.cfs_quota_us", "-1\n"); } -static uint64_t cgroup_cpu_shares_to_weight(uint64_t shares) { - return CLAMP(shares * CGROUP_WEIGHT_DEFAULT / CGROUP_CPU_SHARES_DEFAULT, - CGROUP_WEIGHT_MIN, CGROUP_WEIGHT_MAX); -} - static uint64_t cgroup_cpu_weight_to_shares(uint64_t weight) { /* we don't support idle in cgroupv1 */ if (weight == CGROUP_WEIGHT_IDLE) @@ -1596,14 +1464,6 @@ static bool cgroup_context_has_io_config(CGroupContext *c) { c->io_device_limits; } -static bool cgroup_context_has_blockio_config(CGroupContext *c) { - return c->blockio_accounting || - c->blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID || - c->startup_blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID || - c->blockio_device_weights || - c->blockio_device_bandwidths; -} - static uint64_t cgroup_context_io_weight(CGroupContext *c, ManagerState state) { if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) && c->startup_io_weight != CGROUP_WEIGHT_INVALID) @@ -1613,32 +1473,12 @@ static uint64_t cgroup_context_io_weight(CGroupContext *c, ManagerState state) { return CGROUP_WEIGHT_DEFAULT; } -static uint64_t cgroup_context_blkio_weight(CGroupContext *c, ManagerState state) { - if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) && - c->startup_blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID) - return c->startup_blockio_weight; - if (c->blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID) - return c->blockio_weight; - return CGROUP_BLKIO_WEIGHT_DEFAULT; -} - -static uint64_t cgroup_weight_blkio_to_io(uint64_t blkio_weight) { - return CLAMP(blkio_weight * CGROUP_WEIGHT_DEFAULT / CGROUP_BLKIO_WEIGHT_DEFAULT, - CGROUP_WEIGHT_MIN, CGROUP_WEIGHT_MAX); -} - static uint64_t cgroup_weight_io_to_blkio(uint64_t io_weight) { return CLAMP(io_weight * CGROUP_BLKIO_WEIGHT_DEFAULT / CGROUP_WEIGHT_DEFAULT, CGROUP_BLKIO_WEIGHT_MIN, CGROUP_BLKIO_WEIGHT_MAX); } static int set_bfq_weight(Unit *u, const char *controller, dev_t dev, uint64_t io_weight) { - static const char * const prop_names[] = { - "IOWeight", - "BlockIOWeight", - "IODeviceWeight", - "BlockIODeviceWeight", - }; static bool warned = false; char buf[DECIMAL_STR_MAX(dev_t)*2+2+DECIMAL_STR_MAX(uint64_t)+STRLEN("\n")]; const char *p; @@ -1677,7 +1517,7 @@ static int set_bfq_weight(Unit *u, const char *controller, dev_t dev, uint64_t i r = -EOPNOTSUPP; /* mask as unconfigured device */ } else if (r >= 0 && io_weight != bfq_weight) log_unit_debug(u, "%s=%" PRIu64 " scaled to %s=%" PRIu64, - prop_names[2*(major(dev) > 0) + streq(controller, "blkio")], + major(dev) > 0 ? "IODeviceWeight" : "IOWeight", io_weight, p, bfq_weight); return r; } @@ -1986,7 +1826,6 @@ static void cgroup_context_apply( ManagerState state) { bool is_host_root, is_local_root; - const char *path; CGroupContext *c; int r; @@ -2007,11 +1846,6 @@ static void cgroup_context_apply( if (!crt || !crt->cgroup_path) return; - path = crt->cgroup_path; - - if (is_local_root) /* Make sure we don't try to display messages with an empty path. */ - path = "/"; - /* We generally ignore errors caused by read-only mounted cgroup trees (assuming we are running in a container * then), and missing cgroups, i.e. EROFS and ENOENT. */ @@ -2027,15 +1861,7 @@ static void cgroup_context_apply( if (cgroup_context_has_cpu_weight(c)) weight = cgroup_context_cpu_weight(c, state); - else if (cgroup_context_has_cpu_shares(c)) { - uint64_t shares; - - shares = cgroup_context_cpu_shares(c, state); - weight = cgroup_cpu_shares_to_weight(shares); - - log_cgroup_compat(u, "Applying [Startup]CPUShares=%" PRIu64 " as [Startup]CPUWeight=%" PRIu64 " on %s", - shares, weight, path); - } else + else weight = CGROUP_WEIGHT_DEFAULT; cgroup_apply_unified_cpu_idle(u, weight); @@ -2050,12 +1876,7 @@ static void cgroup_context_apply( weight = cgroup_context_cpu_weight(c, state); shares = cgroup_cpu_weight_to_shares(weight); - - log_cgroup_compat(u, "Applying [Startup]CPUWeight=%" PRIu64 " as [Startup]CPUShares=%" PRIu64 " on %s", - weight, shares, path); - } else if (cgroup_context_has_cpu_shares(c)) - shares = cgroup_context_cpu_shares(c, state); - else + } else shares = CGROUP_CPU_SHARES_DEFAULT; cgroup_apply_legacy_cpu_shares(u, shares); @@ -2072,23 +1893,14 @@ static void cgroup_context_apply( * controller), and in case of containers we want to leave control of these attributes to the container manager * (and we couldn't access that stuff anyway, even if we tried if proper delegation is used). */ if ((apply_mask & CGROUP_MASK_IO) && !is_local_root) { - bool has_io, has_blockio; + bool has_io; uint64_t weight; has_io = cgroup_context_has_io_config(c); - has_blockio = cgroup_context_has_blockio_config(c); if (has_io) weight = cgroup_context_io_weight(c, state); - else if (has_blockio) { - uint64_t blkio_weight; - - blkio_weight = cgroup_context_blkio_weight(c, state); - weight = cgroup_weight_blkio_to_io(blkio_weight); - - log_cgroup_compat(u, "Applying [Startup]BlockIOWeight=%" PRIu64 " as [Startup]IOWeight=%" PRIu64, - blkio_weight, weight); - } else + else weight = CGROUP_WEIGHT_DEFAULT; set_io_weight(u, weight); @@ -2102,55 +1914,21 @@ static void cgroup_context_apply( LIST_FOREACH(device_latencies, latency, c->io_device_latencies) cgroup_apply_io_device_latency(u, latency->path, latency->target_usec); - - } else if (has_blockio) { - LIST_FOREACH(device_weights, w, c->blockio_device_weights) { - weight = cgroup_weight_blkio_to_io(w->weight); - - log_cgroup_compat(u, "Applying BlockIODeviceWeight=%" PRIu64 " as IODeviceWeight=%" PRIu64 " for %s", - w->weight, weight, w->path); - - cgroup_apply_io_device_weight(u, w->path, weight); - } - - LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) { - uint64_t limits[_CGROUP_IO_LIMIT_TYPE_MAX]; - - for (CGroupIOLimitType type = 0; type < _CGROUP_IO_LIMIT_TYPE_MAX; type++) - limits[type] = cgroup_io_limit_defaults[type]; - - limits[CGROUP_IO_RBPS_MAX] = b->rbps; - limits[CGROUP_IO_WBPS_MAX] = b->wbps; - - log_cgroup_compat(u, "Applying BlockIO{Read|Write}Bandwidth=%" PRIu64 " %" PRIu64 " as IO{Read|Write}BandwidthMax= for %s", - b->rbps, b->wbps, b->path); - - cgroup_apply_io_device_limit(u, b->path, limits); - } } } if (apply_mask & CGROUP_MASK_BLKIO) { - bool has_io, has_blockio; + bool has_io; has_io = cgroup_context_has_io_config(c); - has_blockio = cgroup_context_has_blockio_config(c); /* Applying a 'weight' never makes sense for the host root cgroup, and for containers this should be * left to our container manager, too. */ if (!is_local_root) { uint64_t weight; - if (has_io) { - uint64_t io_weight; - - io_weight = cgroup_context_io_weight(c, state); + if (has_io) weight = cgroup_weight_io_to_blkio(cgroup_context_io_weight(c, state)); - - log_cgroup_compat(u, "Applying [Startup]IOWeight=%" PRIu64 " as [Startup]BlockIOWeight=%" PRIu64, - io_weight, weight); - } else if (has_blockio) - weight = cgroup_context_blkio_weight(c, state); else weight = CGROUP_BLKIO_WEIGHT_DEFAULT; @@ -2159,30 +1937,16 @@ static void cgroup_context_apply( if (has_io) LIST_FOREACH(device_weights, w, c->io_device_weights) { weight = cgroup_weight_io_to_blkio(w->weight); - - log_cgroup_compat(u, "Applying IODeviceWeight=%" PRIu64 " as BlockIODeviceWeight=%" PRIu64 " for %s", - w->weight, weight, w->path); - cgroup_apply_blkio_device_weight(u, w->path, weight); } - else if (has_blockio) - LIST_FOREACH(device_weights, w, c->blockio_device_weights) - cgroup_apply_blkio_device_weight(u, w->path, w->weight); } /* The bandwidth limits are something that make sense to be applied to the host's root but not container * roots, as there we want the container manager to handle it */ if (is_host_root || !is_local_root) { if (has_io) - LIST_FOREACH(device_limits, l, c->io_device_limits) { - log_cgroup_compat(u, "Applying IO{Read|Write}Bandwidth=%" PRIu64 " %" PRIu64 " as BlockIO{Read|Write}BandwidthMax= for %s", - l->limits[CGROUP_IO_RBPS_MAX], l->limits[CGROUP_IO_WBPS_MAX], l->path); - + LIST_FOREACH(device_limits, l, c->io_device_limits) cgroup_apply_blkio_device_limit(u, l->path, l->limits[CGROUP_IO_RBPS_MAX], l->limits[CGROUP_IO_WBPS_MAX]); - } - else if (has_blockio) - LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) - cgroup_apply_blkio_device_limit(u, b->path, b->rbps, b->wbps); } } @@ -2193,7 +1957,7 @@ static void cgroup_context_apply( if ((apply_mask & CGROUP_MASK_MEMORY) && !is_local_root) { if (cg_all_unified() > 0) { - uint64_t max, swap_max = CGROUP_LIMIT_MAX, zswap_max = CGROUP_LIMIT_MAX, high = CGROUP_LIMIT_MAX; + uint64_t max = CGROUP_LIMIT_MAX, swap_max = CGROUP_LIMIT_MAX, zswap_max = CGROUP_LIMIT_MAX, high = CGROUP_LIMIT_MAX; if (unit_has_unified_memory_config(u)) { bool startup = IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING); @@ -2202,11 +1966,6 @@ static void cgroup_context_apply( max = startup && c->startup_memory_max_set ? c->startup_memory_max : c->memory_max; swap_max = startup && c->startup_memory_swap_max_set ? c->startup_memory_swap_max : c->memory_swap_max; zswap_max = startup && c->startup_memory_zswap_max_set ? c->startup_memory_zswap_max : c->memory_zswap_max; - } else { - max = c->memory_limit; - - if (max != CGROUP_LIMIT_MAX) - log_cgroup_compat(u, "Applying MemoryLimit=%" PRIu64 " as MemoryMax=", max); } cgroup_apply_unified_memory_limit(u, "memory.min", unit_get_ancestor_memory_min(u)); @@ -2223,12 +1982,10 @@ static void cgroup_context_apply( char buf[DECIMAL_STR_MAX(uint64_t) + 1]; uint64_t val; - if (unit_has_unified_memory_config(u)) { + if (unit_has_unified_memory_config(u)) val = c->memory_max; - if (val != CGROUP_LIMIT_MAX) - log_cgroup_compat(u, "Applying MemoryMax=%" PRIu64 " as MemoryLimit=", val); - } else - val = c->memory_limit; + else + val = CGROUP_LIMIT_MAX; if (val == CGROUP_LIMIT_MAX) strncpy(buf, "-1\n", sizeof(buf)); @@ -2377,18 +2134,16 @@ static CGroupMask unit_get_cgroup_mask(Unit *u) { mask |= get_cpu_accounting_mask(); if (cgroup_context_has_cpu_weight(c) || - cgroup_context_has_cpu_shares(c) || c->cpu_quota_per_sec_usec != USEC_INFINITY) mask |= CGROUP_MASK_CPU; if (cgroup_context_has_allowed_cpus(c) || cgroup_context_has_allowed_mems(c)) mask |= CGROUP_MASK_CPUSET; - if (cgroup_context_has_io_config(c) || cgroup_context_has_blockio_config(c)) + if (cgroup_context_has_io_config(c)) mask |= CGROUP_MASK_IO | CGROUP_MASK_BLKIO; if (c->memory_accounting || - c->memory_limit != CGROUP_LIMIT_MAX || unit_has_unified_memory_config(u)) mask |= CGROUP_MASK_MEMORY; diff --git a/src/core/cgroup.h b/src/core/cgroup.h index 66eb90f856c..32a15d06b13 100644 --- a/src/core/cgroup.h +++ b/src/core/cgroup.h @@ -34,8 +34,6 @@ typedef struct CGroupDeviceAllow CGroupDeviceAllow; typedef struct CGroupIODeviceWeight CGroupIODeviceWeight; typedef struct CGroupIODeviceLimit CGroupIODeviceLimit; typedef struct CGroupIODeviceLatency CGroupIODeviceLatency; -typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight; -typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth; typedef struct CGroupBPFForeignProgram CGroupBPFForeignProgram; typedef struct CGroupSocketBindItem CGroupSocketBindItem; typedef struct CGroupRuntime CGroupRuntime; @@ -98,19 +96,6 @@ struct CGroupIODeviceLatency { usec_t target_usec; }; -struct CGroupBlockIODeviceWeight { - LIST_FIELDS(CGroupBlockIODeviceWeight, device_weights); - char *path; - uint64_t weight; -}; - -struct CGroupBlockIODeviceBandwidth { - LIST_FIELDS(CGroupBlockIODeviceBandwidth, device_bandwidths); - char *path; - uint64_t rbps; - uint64_t wbps; -}; - struct CGroupBPFForeignProgram { LIST_FIELDS(CGroupBPFForeignProgram, programs); uint32_t attach_type; @@ -140,7 +125,6 @@ typedef enum CGroupPressureWatch { struct CGroupContext { bool cpu_accounting; bool io_accounting; - bool blockio_accounting; bool memory_accounting; bool tasks_accounting; bool ip_accounting; @@ -212,17 +196,6 @@ struct CGroupContext { Set *restrict_network_interfaces; bool restrict_network_interfaces_is_allow_list; - /* For legacy hierarchies */ - uint64_t cpu_shares; - uint64_t startup_cpu_shares; - - uint64_t blockio_weight; - uint64_t startup_blockio_weight; - LIST_HEAD(CGroupBlockIODeviceWeight, blockio_device_weights); - LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths); - - uint64_t memory_limit; - CGroupDevicePolicy device_policy; LIST_HEAD(CGroupDeviceAllow, device_allow); @@ -396,8 +369,6 @@ void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a); void cgroup_context_free_io_device_weight(CGroupContext *c, CGroupIODeviceWeight *w); void cgroup_context_free_io_device_limit(CGroupContext *c, CGroupIODeviceLimit *l); void cgroup_context_free_io_device_latency(CGroupContext *c, CGroupIODeviceLatency *l); -void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w); -void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b); void cgroup_context_remove_bpf_foreign_program(CGroupContext *c, CGroupBPFForeignProgram *p); void cgroup_context_remove_socket_bind(CGroupSocketBindItem **head); @@ -417,8 +388,6 @@ static inline int cgroup_context_add_bpf_foreign_program_dup(CGroupContext *c, c int cgroup_context_add_io_device_limit_dup(CGroupContext *c, const CGroupIODeviceLimit *l); int cgroup_context_add_io_device_weight_dup(CGroupContext *c, const CGroupIODeviceWeight *w); int cgroup_context_add_io_device_latency_dup(CGroupContext *c, const CGroupIODeviceLatency *l); -int cgroup_context_add_block_io_device_weight_dup(CGroupContext *c, const CGroupBlockIODeviceWeight *w); -int cgroup_context_add_block_io_device_bandwidth_dup(CGroupContext *c, const CGroupBlockIODeviceBandwidth *b); int cgroup_context_add_device_allow_dup(CGroupContext *c, const CGroupDeviceAllow *a); int cgroup_context_add_socket_bind_item_allow_dup(CGroupContext *c, const CGroupSocketBindItem *i); int cgroup_context_add_socket_bind_item_deny_dup(CGroupContext *c, const CGroupSocketBindItem *i); diff --git a/src/core/execute-serialize.c b/src/core/execute-serialize.c index a13d6120808..380d6fa6bbb 100644 --- a/src/core/execute-serialize.c +++ b/src/core/execute-serialize.c @@ -40,10 +40,6 @@ static int exec_cgroup_context_serialize(const CGroupContext *c, FILE *f) { if (r < 0) return r; - r = serialize_bool_elide(f, "exec-cgroup-context-block-io-accounting", c->blockio_accounting); - if (r < 0) - return r; - r = serialize_bool_elide(f, "exec-cgroup-context-memory-accounting", c->memory_accounting); if (r < 0) return r; @@ -72,18 +68,6 @@ static int exec_cgroup_context_serialize(const CGroupContext *c, FILE *f) { return r; } - if (c->cpu_shares != CGROUP_CPU_SHARES_INVALID) { - r = serialize_item_format(f, "exec-cgroup-context-cpu-shares", "%" PRIu64, c->cpu_shares); - if (r < 0) - return r; - } - - if (c->startup_cpu_shares != CGROUP_CPU_SHARES_INVALID) { - r = serialize_item_format(f, "exec-cgroup-context-startup-cpu-shares", "%" PRIu64, c->startup_cpu_shares); - if (r < 0) - return r; - } - if (c->cpu_quota_per_sec_usec != USEC_INFINITY) { r = serialize_usec(f, "exec-cgroup-context-cpu-quota-per-sec-usec", c->cpu_quota_per_sec_usec); if (r < 0) @@ -140,18 +124,6 @@ static int exec_cgroup_context_serialize(const CGroupContext *c, FILE *f) { return r; } - if (c->blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID) { - r = serialize_item_format(f, "exec-cgroup-context-block-io-weight", "%" PRIu64, c->blockio_weight); - if (r < 0) - return r; - } - - if (c->startup_blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID) { - r = serialize_item_format(f, "exec-cgroup-context-startup-block-io-weight", "%" PRIu64, c->startup_blockio_weight); - if (r < 0) - return r; - } - if (c->default_memory_min > 0) { r = serialize_item_format(f, "exec-cgroup-context-default-memory-min", "%" PRIu64, c->default_memory_min); if (r < 0) @@ -234,12 +206,6 @@ static int exec_cgroup_context_serialize(const CGroupContext *c, FILE *f) { if (r < 0) return r; - if (c->memory_limit != CGROUP_LIMIT_MAX) { - r = serialize_item_format(f, "exec-cgroup-context-memory-limit", "%" PRIu64, c->memory_limit); - if (r < 0) - return r; - } - if (c->tasks_max.value != UINT64_MAX) { r = serialize_item_format(f, "exec-cgroup-context-tasks-max-value", "%" PRIu64, c->tasks_max.value); if (r < 0) @@ -390,31 +356,6 @@ static int exec_cgroup_context_serialize(const CGroupContext *c, FILE *f) { return r; } - LIST_FOREACH(device_weights, w, c->blockio_device_weights) { - r = serialize_item_format(f, "exec-cgroup-context-blockio-device-weight", "%s %" PRIu64, - w->path, - w->weight); - if (r < 0) - return r; - } - - LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) { - if (b->rbps != CGROUP_LIMIT_MAX) { - r = serialize_item_format(f, "exec-cgroup-context-blockio-read-bandwidth", "%s %" PRIu64, - b->path, - b->rbps); - if (r < 0) - return r; - } - if (b->wbps != CGROUP_LIMIT_MAX) { - r = serialize_item_format(f, "exec-cgroup-context-blockio-write-bandwidth", "%s %" PRIu64, - b->path, - b->wbps); - if (r < 0) - return r; - } - } - SET_FOREACH(iaai, c->ip_address_allow) { r = serialize_item(f, "exec-cgroup-context-ip-address-allow", @@ -512,11 +453,6 @@ static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) { if (r < 0) return r; c->io_accounting = r; - } else if ((val = startswith(l, "exec-cgroup-context-block-io-accounting="))) { - r = parse_boolean(val); - if (r < 0) - return r; - c->blockio_accounting = r; } else if ((val = startswith(l, "exec-cgroup-context-memory-accounting="))) { r = parse_boolean(val); if (r < 0) @@ -545,14 +481,6 @@ static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) { r = safe_atou64(val, &c->startup_cpu_weight); if (r < 0) return r; - } else if ((val = startswith(l, "exec-cgroup-context-cpu-shares="))) { - r = safe_atou64(val, &c->cpu_shares); - if (r < 0) - return r; - } else if ((val = startswith(l, "exec-cgroup-context-startup-cpu-shares="))) { - r = safe_atou64(val, &c->startup_cpu_shares); - if (r < 0) - return r; } else if ((val = startswith(l, "exec-cgroup-context-cpu-quota-per-sec-usec="))) { r = deserialize_usec(val, &c->cpu_quota_per_sec_usec); if (r < 0) @@ -625,14 +553,6 @@ static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) { r = safe_atou64(val, &c->startup_io_weight); if (r < 0) return r; - } else if ((val = startswith(l, "exec-cgroup-context-block-io-weight="))) { - r = safe_atou64(val, &c->blockio_weight); - if (r < 0) - return r; - } else if ((val = startswith(l, "exec-cgroup-context-startup-block-io-weight="))) { - r = safe_atou64(val, &c->startup_blockio_weight); - if (r < 0) - return r; } else if ((val = startswith(l, "exec-cgroup-context-default-memory-min="))) { r = safe_atou64(val, &c->default_memory_min); if (r < 0) @@ -690,10 +610,6 @@ static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) { if (r < 0) return r; c->memory_zswap_writeback = r; - } else if ((val = startswith(l, "exec-cgroup-context-memory-limit="))) { - r = safe_atou64(val, &c->memory_limit); - if (r < 0) - return r; } else if ((val = startswith(l, "exec-cgroup-context-tasks-max-value="))) { r = safe_atou64(val, &c->tasks_max.value); if (r < 0) @@ -912,87 +828,6 @@ static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) { r = safe_atou64(limits, &limit->limits[t]); if (r < 0) return r; - } else if ((val = startswith(l, "exec-cgroup-context-block-io-device-weight="))) { - _cleanup_free_ char *path = NULL, *weight = NULL; - CGroupBlockIODeviceWeight *a = NULL; - - r = extract_many_words(&val, " ", 0, &path, &weight); - if (r < 0) - return r; - if (r != 2) - return -EINVAL; - - a = new0(CGroupBlockIODeviceWeight, 1); - if (!a) - return log_oom_debug(); - - a->path = TAKE_PTR(path); - - LIST_PREPEND(device_weights, c->blockio_device_weights, a); - - r = safe_atou64(weight, &a->weight); - if (r < 0) - return r; - } else if ((val = startswith(l, "exec-cgroup-context-block-io-read-bandwidth="))) { - _cleanup_free_ char *path = NULL, *bw = NULL; - CGroupBlockIODeviceBandwidth *a = NULL; - - r = extract_many_words(&val, " ", 0, &path, &bw); - if (r < 0) - return r; - if (r != 2) - return -EINVAL; - - LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) - if (path_equal(b->path, path)) { - a = b; - break; - } - - if (!a) { - a = new0(CGroupBlockIODeviceBandwidth, 1); - if (!a) - return log_oom_debug(); - - a->path = TAKE_PTR(path); - a->wbps = CGROUP_LIMIT_MAX; - - LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, a); - } - - r = safe_atou64(bw, &a->rbps); - if (r < 0) - return r; - } else if ((val = startswith(l, "exec-cgroup-context-block-io-write-bandwidth="))) { - _cleanup_free_ char *path = NULL, *bw = NULL; - CGroupBlockIODeviceBandwidth *a = NULL; - - r = extract_many_words(&val, " ", 0, &path, &bw); - if (r < 0) - return r; - if (r != 2) - return -EINVAL; - - LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) - if (path_equal(b->path, path)) { - a = b; - break; - } - - if (!a) { - a = new0(CGroupBlockIODeviceBandwidth, 1); - if (!a) - return log_oom_debug(); - - a->path = TAKE_PTR(path); - a->rbps = CGROUP_LIMIT_MAX; - - LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, a); - } - - r = safe_atou64(bw, &a->wbps); - if (r < 0) - return r; } else if ((val = startswith(l, "exec-cgroup-context-ip-address-allow="))) { struct in_addr_prefix a; diff --git a/src/core/unit.c b/src/core/unit.c index 557630368cc..fa283a8b04a 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -173,7 +173,6 @@ static void unit_init(Unit *u) { cc->cpu_accounting = u->manager->defaults.cpu_accounting; cc->io_accounting = u->manager->defaults.io_accounting; - cc->blockio_accounting = u->manager->defaults.blockio_accounting; cc->memory_accounting = u->manager->defaults.memory_accounting; cc->tasks_accounting = u->manager->defaults.tasks_accounting; cc->ip_accounting = u->manager->defaults.ip_accounting; From f1c5534eb61a1abcac62d67d57ef2f0715073819 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 16 Apr 2025 03:19:16 +0900 Subject: [PATCH 07/16] core/cgroup: remove logic of CGroup v1 attribute assignment --- src/core/cgroup.c | 209 +++++++--------------------------------------- 1 file changed, 29 insertions(+), 180 deletions(-) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index bc4378bca4b..0b798e0a23c 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -1412,37 +1412,6 @@ static void cgroup_apply_unified_cpu_quota(Unit *u, usec_t quota, usec_t period) (void) set_attribute_and_warn(u, "cpu", "cpu.max", buf); } -static void cgroup_apply_legacy_cpu_shares(Unit *u, uint64_t shares) { - char buf[DECIMAL_STR_MAX(uint64_t) + 2]; - - xsprintf(buf, "%" PRIu64 "\n", shares); - (void) set_attribute_and_warn(u, "cpu", "cpu.shares", buf); -} - -static void cgroup_apply_legacy_cpu_quota(Unit *u, usec_t quota, usec_t period) { - char buf[DECIMAL_STR_MAX(usec_t) + 2]; - - period = cgroup_cpu_adjust_period_and_log(u, period, quota); - - xsprintf(buf, USEC_FMT "\n", period); - (void) set_attribute_and_warn(u, "cpu", "cpu.cfs_period_us", buf); - - if (quota != USEC_INFINITY) { - xsprintf(buf, USEC_FMT "\n", MAX(quota * period / USEC_PER_SEC, USEC_PER_MSEC)); - (void) set_attribute_and_warn(u, "cpu", "cpu.cfs_quota_us", buf); - } else - (void) set_attribute_and_warn(u, "cpu", "cpu.cfs_quota_us", "-1\n"); -} - -static uint64_t cgroup_cpu_weight_to_shares(uint64_t weight) { - /* we don't support idle in cgroupv1 */ - if (weight == CGROUP_WEIGHT_IDLE) - return CGROUP_CPU_SHARES_MIN; - - return CLAMP(weight * CGROUP_CPU_SHARES_DEFAULT / CGROUP_WEIGHT_DEFAULT, - CGROUP_CPU_SHARES_MIN, CGROUP_CPU_SHARES_MAX); -} - static void cgroup_apply_unified_cpuset(Unit *u, const CPUSet *cpus, const char *name) { _cleanup_free_ char *buf = NULL; @@ -1473,11 +1442,6 @@ static uint64_t cgroup_context_io_weight(CGroupContext *c, ManagerState state) { return CGROUP_WEIGHT_DEFAULT; } -static uint64_t cgroup_weight_io_to_blkio(uint64_t io_weight) { - return CLAMP(io_weight * CGROUP_BLKIO_WEIGHT_DEFAULT / CGROUP_WEIGHT_DEFAULT, - CGROUP_BLKIO_WEIGHT_MIN, CGROUP_BLKIO_WEIGHT_MAX); -} - static int set_bfq_weight(Unit *u, const char *controller, dev_t dev, uint64_t io_weight) { static bool warned = false; char buf[DECIMAL_STR_MAX(dev_t)*2+2+DECIMAL_STR_MAX(uint64_t)+STRLEN("\n")]; @@ -1550,19 +1514,6 @@ static void cgroup_apply_io_device_weight(Unit *u, const char *dev_path, uint64_ empty_to_root(crt->cgroup_path), (int) strcspn(buf, NEWLINE), buf); } -static void cgroup_apply_blkio_device_weight(Unit *u, const char *dev_path, uint64_t blkio_weight) { - char buf[DECIMAL_STR_MAX(dev_t)*2+2+DECIMAL_STR_MAX(uint64_t)+1]; - dev_t dev; - int r; - - r = lookup_block_device(dev_path, &dev); - if (r < 0) - return; - - xsprintf(buf, DEVNUM_FORMAT_STR " %" PRIu64 "\n", DEVNUM_FORMAT_VAL(dev), blkio_weight); - (void) set_attribute_and_warn(u, "blkio", "blkio.weight_device", buf); -} - static void cgroup_apply_io_device_latency(Unit *u, const char *dev_path, usec_t target) { char buf[DECIMAL_STR_MAX(dev_t)*2+2+7+DECIMAL_STR_MAX(uint64_t)+1]; dev_t dev; @@ -1600,20 +1551,6 @@ static void cgroup_apply_io_device_limit(Unit *u, const char *dev_path, uint64_t (void) set_attribute_and_warn(u, "io", "io.max", buf); } -static void cgroup_apply_blkio_device_limit(Unit *u, const char *dev_path, uint64_t rbps, uint64_t wbps) { - char buf[DECIMAL_STR_MAX(dev_t)*2+2+DECIMAL_STR_MAX(uint64_t)+1]; - dev_t dev; - - if (lookup_block_device(dev_path, &dev) < 0) - return; - - sprintf(buf, DEVNUM_FORMAT_STR " %" PRIu64 "\n", DEVNUM_FORMAT_VAL(dev), rbps); - (void) set_attribute_and_warn(u, "blkio", "blkio.throttle.read_bps_device", buf); - - sprintf(buf, DEVNUM_FORMAT_STR " %" PRIu64 "\n", DEVNUM_FORMAT_VAL(dev), wbps); - (void) set_attribute_and_warn(u, "blkio", "blkio.throttle.write_bps_device", buf); -} - static bool unit_has_unified_memory_config(Unit *u) { CGroupContext *c; @@ -1803,17 +1740,6 @@ static void set_io_weight(Unit *u, uint64_t weight) { (void) set_attribute_and_warn(u, "io", "io.weight", buf); } -static void set_blkio_weight(Unit *u, uint64_t weight) { - char buf[STRLEN("\n")+DECIMAL_STR_MAX(uint64_t)]; - - assert(u); - - (void) set_bfq_weight(u, "blkio", makedev(0, 0), weight); - - xsprintf(buf, "%" PRIu64 "\n", weight); - (void) set_attribute_and_warn(u, "blkio", "blkio.weight", buf); -} - static void cgroup_apply_bpf_foreign_program(Unit *u) { assert(u); @@ -1849,39 +1775,18 @@ static void cgroup_context_apply( /* We generally ignore errors caused by read-only mounted cgroup trees (assuming we are running in a container * then), and missing cgroups, i.e. EROFS and ENOENT. */ - /* In fully unified mode these attributes don't exist on the host cgroup root. On legacy the weights exist, but - * setting the weight makes very little sense on the host root cgroup, as there are no other cgroups at this - * level. The quota exists there too, but any attempt to write to it is refused with EINVAL. Inside of - * containers we want to leave control of these to the container manager (and if cgroup v2 delegation is used - * we couldn't even write to them if we wanted to). */ + /* These attributes don't exist on the host cgroup root. */ if ((apply_mask & CGROUP_MASK_CPU) && !is_local_root) { + uint64_t weight; - if (cg_all_unified() > 0) { - uint64_t weight; + if (cgroup_context_has_cpu_weight(c)) + weight = cgroup_context_cpu_weight(c, state); + else + weight = CGROUP_WEIGHT_DEFAULT; - if (cgroup_context_has_cpu_weight(c)) - weight = cgroup_context_cpu_weight(c, state); - else - weight = CGROUP_WEIGHT_DEFAULT; - - cgroup_apply_unified_cpu_idle(u, weight); - cgroup_apply_unified_cpu_weight(u, weight); - cgroup_apply_unified_cpu_quota(u, c->cpu_quota_per_sec_usec, c->cpu_quota_period_usec); - - } else { - uint64_t shares; - - if (cgroup_context_has_cpu_weight(c)) { - uint64_t weight; - - weight = cgroup_context_cpu_weight(c, state); - shares = cgroup_cpu_weight_to_shares(weight); - } else - shares = CGROUP_CPU_SHARES_DEFAULT; - - cgroup_apply_legacy_cpu_shares(u, shares); - cgroup_apply_legacy_cpu_quota(u, c->cpu_quota_per_sec_usec, c->cpu_quota_period_usec); - } + cgroup_apply_unified_cpu_idle(u, weight); + cgroup_apply_unified_cpu_weight(u, weight); + cgroup_apply_unified_cpu_quota(u, c->cpu_quota_per_sec_usec, c->cpu_quota_period_usec); } if ((apply_mask & CGROUP_MASK_CPUSET) && !is_local_root) { @@ -1917,89 +1822,33 @@ static void cgroup_context_apply( } } - if (apply_mask & CGROUP_MASK_BLKIO) { - bool has_io; - - has_io = cgroup_context_has_io_config(c); - - /* Applying a 'weight' never makes sense for the host root cgroup, and for containers this should be - * left to our container manager, too. */ - if (!is_local_root) { - uint64_t weight; - - if (has_io) - weight = cgroup_weight_io_to_blkio(cgroup_context_io_weight(c, state)); - else - weight = CGROUP_BLKIO_WEIGHT_DEFAULT; - - set_blkio_weight(u, weight); - - if (has_io) - LIST_FOREACH(device_weights, w, c->io_device_weights) { - weight = cgroup_weight_io_to_blkio(w->weight); - cgroup_apply_blkio_device_weight(u, w->path, weight); - } - } - - /* The bandwidth limits are something that make sense to be applied to the host's root but not container - * roots, as there we want the container manager to handle it */ - if (is_host_root || !is_local_root) { - if (has_io) - LIST_FOREACH(device_limits, l, c->io_device_limits) - cgroup_apply_blkio_device_limit(u, l->path, l->limits[CGROUP_IO_RBPS_MAX], l->limits[CGROUP_IO_WBPS_MAX]); - } - } - - /* In unified mode 'memory' attributes do not exist on the root cgroup. In legacy mode 'memory.limit_in_bytes' - * exists on the root cgroup, but any writes to it are refused with EINVAL. And if we run in a container we - * want to leave control to the container manager (and if proper cgroup v2 delegation is used we couldn't even - * write to this if we wanted to.) */ + /* 'memory' attributes do not exist on the root cgroup. */ if ((apply_mask & CGROUP_MASK_MEMORY) && !is_local_root) { + uint64_t max = CGROUP_LIMIT_MAX, swap_max = CGROUP_LIMIT_MAX, zswap_max = CGROUP_LIMIT_MAX, high = CGROUP_LIMIT_MAX; - if (cg_all_unified() > 0) { - uint64_t max = CGROUP_LIMIT_MAX, swap_max = CGROUP_LIMIT_MAX, zswap_max = CGROUP_LIMIT_MAX, high = CGROUP_LIMIT_MAX; + if (unit_has_unified_memory_config(u)) { + bool startup = IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING); - if (unit_has_unified_memory_config(u)) { - bool startup = IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING); - - high = startup && c->startup_memory_high_set ? c->startup_memory_high : c->memory_high; - max = startup && c->startup_memory_max_set ? c->startup_memory_max : c->memory_max; - swap_max = startup && c->startup_memory_swap_max_set ? c->startup_memory_swap_max : c->memory_swap_max; - zswap_max = startup && c->startup_memory_zswap_max_set ? c->startup_memory_zswap_max : c->memory_zswap_max; - } - - cgroup_apply_unified_memory_limit(u, "memory.min", unit_get_ancestor_memory_min(u)); - cgroup_apply_unified_memory_limit(u, "memory.low", unit_get_ancestor_memory_low(u)); - cgroup_apply_unified_memory_limit(u, "memory.high", high); - cgroup_apply_unified_memory_limit(u, "memory.max", max); - cgroup_apply_unified_memory_limit(u, "memory.swap.max", swap_max); - cgroup_apply_unified_memory_limit(u, "memory.zswap.max", zswap_max); - - (void) set_attribute_and_warn(u, "memory", "memory.oom.group", one_zero(c->memory_oom_group)); - (void) set_attribute_and_warn(u, "memory", "memory.zswap.writeback", one_zero(c->memory_zswap_writeback)); - - } else { - char buf[DECIMAL_STR_MAX(uint64_t) + 1]; - uint64_t val; - - if (unit_has_unified_memory_config(u)) - val = c->memory_max; - else - val = CGROUP_LIMIT_MAX; - - if (val == CGROUP_LIMIT_MAX) - strncpy(buf, "-1\n", sizeof(buf)); - else - xsprintf(buf, "%" PRIu64 "\n", val); - - (void) set_attribute_and_warn(u, "memory", "memory.limit_in_bytes", buf); + high = startup && c->startup_memory_high_set ? c->startup_memory_high : c->memory_high; + max = startup && c->startup_memory_max_set ? c->startup_memory_max : c->memory_max; + swap_max = startup && c->startup_memory_swap_max_set ? c->startup_memory_swap_max : c->memory_swap_max; + zswap_max = startup && c->startup_memory_zswap_max_set ? c->startup_memory_zswap_max : c->memory_zswap_max; } + + cgroup_apply_unified_memory_limit(u, "memory.min", unit_get_ancestor_memory_min(u)); + cgroup_apply_unified_memory_limit(u, "memory.low", unit_get_ancestor_memory_low(u)); + cgroup_apply_unified_memory_limit(u, "memory.high", high); + cgroup_apply_unified_memory_limit(u, "memory.max", max); + cgroup_apply_unified_memory_limit(u, "memory.swap.max", swap_max); + cgroup_apply_unified_memory_limit(u, "memory.zswap.max", zswap_max); + + (void) set_attribute_and_warn(u, "memory", "memory.oom.group", one_zero(c->memory_oom_group)); + (void) set_attribute_and_warn(u, "memory", "memory.zswap.writeback", one_zero(c->memory_zswap_writeback)); } - /* On cgroup v2 we can apply BPF everywhere. On cgroup v1 we apply it everywhere except for the root of - * containers, where we leave this to the manager */ + /* On cgroup v2 we can apply BPF everywhere. */ if ((apply_mask & (CGROUP_MASK_DEVICES | CGROUP_MASK_BPF_DEVICES)) && - (is_host_root || cg_all_unified() > 0 || !is_local_root)) + (is_host_root || !is_local_root)) (void) cgroup_apply_devices(u); if (apply_mask & CGROUP_MASK_PIDS) { From 08183002889ca0621955a4ea9e285c26e8e900e6 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 8 Apr 2025 17:16:56 +0900 Subject: [PATCH 08/16] core/cgroup: drop unnecessary _unified_ modifier from function names --- src/core/cgroup.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 0b798e0a23c..d55c50b3180 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -1370,7 +1370,7 @@ static usec_t cgroup_cpu_adjust_period_and_log(Unit *u, usec_t period, usec_t qu return new_period; } -static void cgroup_apply_unified_cpu_weight(Unit *u, uint64_t weight) { +static void cgroup_apply_cpu_weight(Unit *u, uint64_t weight) { char buf[DECIMAL_STR_MAX(uint64_t) + 2]; if (weight == CGROUP_WEIGHT_IDLE) @@ -1379,7 +1379,7 @@ static void cgroup_apply_unified_cpu_weight(Unit *u, uint64_t weight) { (void) set_attribute_and_warn(u, "cpu", "cpu.weight", buf); } -static void cgroup_apply_unified_cpu_idle(Unit *u, uint64_t weight) { +static void cgroup_apply_cpu_idle(Unit *u, uint64_t weight) { int r; bool is_idle; const char *idle_val; @@ -1398,7 +1398,7 @@ static void cgroup_apply_unified_cpu_idle(Unit *u, uint64_t weight) { "cpu.idle", empty_to_root(crt->cgroup_path), idle_val); } -static void cgroup_apply_unified_cpu_quota(Unit *u, usec_t quota, usec_t period) { +static void cgroup_apply_cpu_quota(Unit *u, usec_t quota, usec_t period) { char buf[(DECIMAL_STR_MAX(usec_t) + 1) * 2 + 1]; assert(u); @@ -1412,7 +1412,7 @@ static void cgroup_apply_unified_cpu_quota(Unit *u, usec_t quota, usec_t period) (void) set_attribute_and_warn(u, "cpu", "cpu.max", buf); } -static void cgroup_apply_unified_cpuset(Unit *u, const CPUSet *cpus, const char *name) { +static void cgroup_apply_cpuset(Unit *u, const CPUSet *cpus, const char *name) { _cleanup_free_ char *buf = NULL; buf = cpu_set_to_range_string(cpus); @@ -1551,7 +1551,7 @@ static void cgroup_apply_io_device_limit(Unit *u, const char *dev_path, uint64_t (void) set_attribute_and_warn(u, "io", "io.max", buf); } -static bool unit_has_unified_memory_config(Unit *u) { +static bool unit_has_memory_config(Unit *u) { CGroupContext *c; assert(u); @@ -1566,7 +1566,7 @@ static bool unit_has_unified_memory_config(Unit *u) { c->memory_zswap_max != CGROUP_LIMIT_MAX || c->startup_memory_zswap_max_set; } -static void cgroup_apply_unified_memory_limit(Unit *u, const char *file, uint64_t v) { +static void cgroup_apply_memory_limit(Unit *u, const char *file, uint64_t v) { char buf[DECIMAL_STR_MAX(uint64_t) + 1] = "max\n"; if (v != CGROUP_LIMIT_MAX) @@ -1784,14 +1784,14 @@ static void cgroup_context_apply( else weight = CGROUP_WEIGHT_DEFAULT; - cgroup_apply_unified_cpu_idle(u, weight); - cgroup_apply_unified_cpu_weight(u, weight); - cgroup_apply_unified_cpu_quota(u, c->cpu_quota_per_sec_usec, c->cpu_quota_period_usec); + cgroup_apply_cpu_idle(u, weight); + cgroup_apply_cpu_weight(u, weight); + cgroup_apply_cpu_quota(u, c->cpu_quota_per_sec_usec, c->cpu_quota_period_usec); } if ((apply_mask & CGROUP_MASK_CPUSET) && !is_local_root) { - cgroup_apply_unified_cpuset(u, cgroup_context_allowed_cpus(c, state), "cpuset.cpus"); - cgroup_apply_unified_cpuset(u, cgroup_context_allowed_mems(c, state), "cpuset.mems"); + cgroup_apply_cpuset(u, cgroup_context_allowed_cpus(c, state), "cpuset.cpus"); + cgroup_apply_cpuset(u, cgroup_context_allowed_mems(c, state), "cpuset.mems"); } /* The 'io' controller attributes are not exported on the host's root cgroup (being a pure cgroup v2 @@ -1826,7 +1826,7 @@ static void cgroup_context_apply( if ((apply_mask & CGROUP_MASK_MEMORY) && !is_local_root) { uint64_t max = CGROUP_LIMIT_MAX, swap_max = CGROUP_LIMIT_MAX, zswap_max = CGROUP_LIMIT_MAX, high = CGROUP_LIMIT_MAX; - if (unit_has_unified_memory_config(u)) { + if (unit_has_memory_config(u)) { bool startup = IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING); high = startup && c->startup_memory_high_set ? c->startup_memory_high : c->memory_high; @@ -1835,12 +1835,12 @@ static void cgroup_context_apply( zswap_max = startup && c->startup_memory_zswap_max_set ? c->startup_memory_zswap_max : c->memory_zswap_max; } - cgroup_apply_unified_memory_limit(u, "memory.min", unit_get_ancestor_memory_min(u)); - cgroup_apply_unified_memory_limit(u, "memory.low", unit_get_ancestor_memory_low(u)); - cgroup_apply_unified_memory_limit(u, "memory.high", high); - cgroup_apply_unified_memory_limit(u, "memory.max", max); - cgroup_apply_unified_memory_limit(u, "memory.swap.max", swap_max); - cgroup_apply_unified_memory_limit(u, "memory.zswap.max", zswap_max); + cgroup_apply_memory_limit(u, "memory.min", unit_get_ancestor_memory_min(u)); + cgroup_apply_memory_limit(u, "memory.low", unit_get_ancestor_memory_low(u)); + cgroup_apply_memory_limit(u, "memory.high", high); + cgroup_apply_memory_limit(u, "memory.max", max); + cgroup_apply_memory_limit(u, "memory.swap.max", swap_max); + cgroup_apply_memory_limit(u, "memory.zswap.max", zswap_max); (void) set_attribute_and_warn(u, "memory", "memory.oom.group", one_zero(c->memory_oom_group)); (void) set_attribute_and_warn(u, "memory", "memory.zswap.writeback", one_zero(c->memory_zswap_writeback)); @@ -1993,7 +1993,7 @@ static CGroupMask unit_get_cgroup_mask(Unit *u) { mask |= CGROUP_MASK_IO | CGROUP_MASK_BLKIO; if (c->memory_accounting || - unit_has_unified_memory_config(u)) + unit_has_memory_config(u)) mask |= CGROUP_MASK_MEMORY; if (c->device_allow || From 35f88201f27a2c4fa1d1defa9004300156be0f63 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 7 Apr 2025 03:16:53 +0900 Subject: [PATCH 09/16] core/cgroup: drop unnecessary cgroup version check in several getters After 2b61489e5a53eb2611e1e573519c209ca07de98e, these checks are not necessary anymore. --- src/core/cgroup.c | 51 ++--------------------------------------------- 1 file changed, 2 insertions(+), 49 deletions(-) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index d55c50b3180..e1371c94f35 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -537,8 +537,7 @@ static int unit_compare_memory_limit(Unit *u, const char *property_name, uint64_ uint64_t unit_value; int r; - /* Compare kernel memcg configuration against our internal systemd state. Unsupported (and will - * return -ENODATA) on cgroup v1. + /* Compare kernel memcg configuration against our internal systemd state. * * Returns: * @@ -553,17 +552,6 @@ static int unit_compare_memory_limit(Unit *u, const char *property_name, uint64_ assert(u); - r = cg_all_unified(); - if (r < 0) - return log_debug_errno(r, "Failed to determine cgroup hierarchy version: %m"); - - /* Unsupported on v1. - * - * We don't return ENOENT, since that could actually mask a genuine problem where somebody else has - * silently masked the controller. */ - if (r == 0) - return -ENODATA; - /* The root slice doesn't have any controller files, so we can't compare anything. */ if (unit_has_name(u, SPECIAL_ROOT_SLICE)) return -ENODATA; @@ -2047,22 +2035,13 @@ CGroupMask unit_get_own_mask(Unit *u) { CGroupMask unit_get_delegate_mask(Unit *u) { CGroupContext *c; - /* If delegation is turned on, then turn on selected controllers, unless we are on the legacy hierarchy and the - * process we fork into is known to drop privileges, and hence shouldn't get access to the controllers. + /* If delegation is turned on, then turn on selected controllers. * * Note that on the unified hierarchy it is safe to delegate controllers to unprivileged services. */ if (!unit_cgroup_delegate(u)) return 0; - if (cg_all_unified() <= 0) { - ExecContext *e; - - e = unit_get_exec_context(u); - if (e && !exec_context_maintains_privileges(e)) - return 0; - } - assert_se(c = unit_get_cgroup_context(u)); return CGROUP_MASK_EXTEND_JOINED(c->delegate_controllers); } @@ -3376,12 +3355,6 @@ int unit_check_oomd_kill(Unit *u) { if (!crt || !crt->cgroup_path) return 0; - r = cg_all_unified(); - if (r < 0) - return log_unit_debug_errno(u, r, "Couldn't determine whether we are in all unified mode: %m"); - if (r == 0) - return 0; - r = cg_get_xattr_malloc(crt->cgroup_path, "user.oomd_ooms", &value, /* ret_size= */ NULL); if (r < 0 && !ERRNO_IS_XATTR_ABSENT(r)) return r; @@ -4007,12 +3980,6 @@ static int unit_get_cpu_usage_raw(const Unit *u, const CGroupRuntime *crt, nsec_ if ((get_cpu_accounting_mask() & ~crt->cgroup_realized_mask) != 0) return -ENODATA; - r = cg_all_unified(); - if (r < 0) - return r; - if (r == 0) - return cg_get_attribute_as_uint64("cpuacct", crt->cgroup_path, "cpuacct.usage", ret); - _cleanup_free_ char *val = NULL; uint64_t us; @@ -4133,8 +4100,6 @@ static uint64_t unit_get_effective_limit_one(Unit *u, CGroupLimitType type) { cc = ASSERT_PTR(unit_get_cgroup_context(u)); switch (type) { - /* Note: on legacy/hybrid hierarchies memory_max stays CGROUP_LIMIT_MAX unless configured - * explicitly. Effective value of MemoryLimit= (cgroup v1) is not implemented. */ case CGROUP_LIMIT_MEMORY_MAX: return cc->memory_max; case CGROUP_LIMIT_MEMORY_HIGH: @@ -4191,12 +4156,6 @@ static int unit_get_io_accounting_raw( if (unit_has_host_root_cgroup(u)) return -ENODATA; /* TODO: return useful data for the top-level cgroup */ - r = cg_all_unified(); - if (r < 0) - return r; - if (r == 0) - return -ENODATA; - if (!FLAGS_SET(crt->cgroup_realized_mask, CGROUP_MASK_IO)) return -ENODATA; @@ -4589,12 +4548,6 @@ int unit_get_cpuset(Unit *u, CPUSet *cpus, const char *name) { if ((crt->cgroup_realized_mask & CGROUP_MASK_CPUSET) == 0) return -ENODATA; - r = cg_all_unified(); - if (r < 0) - return r; - if (r == 0) - return -ENODATA; - r = cg_get_attribute("cpuset", crt->cgroup_path, name, &v); if (r == -ENOENT) return -ENODATA; From 4ee64e436573a8885b59c1494f87ee391253f0ae Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 16 Apr 2025 03:29:55 +0900 Subject: [PATCH 10/16] core/cgroup: drop cgroup v1 specific code in unit_update_cgroup() --- src/core/cgroup.c | 74 ++++++++--------------------------------------- src/core/cgroup.h | 1 - 2 files changed, 12 insertions(+), 63 deletions(-) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index e1371c94f35..da7c816338e 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -2174,31 +2174,6 @@ void unit_invalidate_cgroup_members_masks(Unit *u) { unit_invalidate_cgroup_members_masks(slice); } -const char* unit_get_realized_cgroup_path(Unit *u, CGroupMask mask) { - - /* Returns the realized cgroup path of the specified unit where all specified controllers are available. */ - - while (u) { - CGroupRuntime *crt = unit_get_cgroup_runtime(u); - if (crt && - crt->cgroup_path && - crt->cgroup_realized && - FLAGS_SET(crt->cgroup_realized_mask, mask)) - return crt->cgroup_path; - - u = UNIT_GET_SLICE(u); - } - - return NULL; -} - -static const char *migrate_callback(CGroupMask mask, void *userdata) { - /* If not realized at all, migrate to root (""). - * It may happen if we're upgrading from older version that didn't clean up. - */ - return strempty(unit_get_realized_cgroup_path(userdata, mask)); -} - int unit_default_cgroup_path(const Unit *u, char **ret) { _cleanup_free_ char *p = NULL; int r; @@ -2415,8 +2390,7 @@ static int unit_update_cgroup( CGroupMask enable_mask, ManagerState state) { - bool created, is_root_slice; - CGroupMask migrate_mask = 0; + bool created; _cleanup_free_ char *cgroup_full_path = NULL; int r; @@ -2441,27 +2415,23 @@ static int unit_update_cgroup( return log_unit_error_errno(u, r, "Failed to create cgroup %s: %m", empty_to_root(crt->cgroup_path)); created = r; - if (cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER) > 0) { - uint64_t cgroup_id = 0; + uint64_t cgroup_id = 0; + r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, NULL, &cgroup_full_path); + if (r == 0) { + r = cg_path_get_cgroupid(cgroup_full_path, &cgroup_id); + if (r < 0) + log_unit_full_errno(u, ERRNO_IS_NOT_SUPPORTED(r) ? LOG_DEBUG : LOG_WARNING, r, + "Failed to get cgroup ID of cgroup %s, ignoring: %m", cgroup_full_path); + } else + log_unit_warning_errno(u, r, "Failed to get full cgroup path on cgroup %s, ignoring: %m", empty_to_root(crt->cgroup_path)); - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, crt->cgroup_path, NULL, &cgroup_full_path); - if (r == 0) { - r = cg_path_get_cgroupid(cgroup_full_path, &cgroup_id); - if (r < 0) - log_unit_full_errno(u, ERRNO_IS_NOT_SUPPORTED(r) ? LOG_DEBUG : LOG_WARNING, r, - "Failed to get cgroup ID of cgroup %s, ignoring: %m", cgroup_full_path); - } else - log_unit_warning_errno(u, r, "Failed to get full cgroup path on cgroup %s, ignoring: %m", empty_to_root(crt->cgroup_path)); - - crt->cgroup_id = cgroup_id; - } + crt->cgroup_id = cgroup_id; /* Start watching it */ (void) unit_watch_cgroup(u); (void) unit_watch_cgroup_memory(u); - /* For v2 we preserve enabled controllers in delegated units, adjust others, - * for v1 we figure out which controller hierarchies need migration. */ + /* For v2 we preserve enabled controllers in delegated units, adjust others, */ if (created || !crt->cgroup_realized || !unit_cgroup_delegate(u)) { CGroupMask result_mask = 0; @@ -2472,32 +2442,12 @@ static int unit_update_cgroup( /* Remember what's actually enabled now */ crt->cgroup_enabled_mask = result_mask; - - migrate_mask = crt->cgroup_realized_mask ^ target_mask; } /* Keep track that this is now realized */ crt->cgroup_realized = true; crt->cgroup_realized_mask = target_mask; - /* Migrate processes in controller hierarchies both downwards (enabling) and upwards (disabling). - * - * Unnecessary controller cgroups are trimmed (after emptied by upward migration). - * We perform migration also with whole slices for cases when users don't care about leave - * granularity. Since delegated_mask is subset of target mask, we won't trim slice subtree containing - * delegated units. - */ - if (cg_all_unified() == 0) { - r = cg_migrate_v1_controllers(u->manager->cgroup_supported, migrate_mask, crt->cgroup_path, migrate_callback, u); - if (r < 0) - log_unit_warning_errno(u, r, "Failed to migrate controller cgroups from %s, ignoring: %m", empty_to_root(crt->cgroup_path)); - - is_root_slice = unit_has_name(u, SPECIAL_ROOT_SLICE); - r = cg_trim_v1_controllers(u->manager->cgroup_supported, ~target_mask, crt->cgroup_path, !is_root_slice); - if (r < 0) - log_unit_warning_errno(u, r, "Failed to delete controller cgroups %s, ignoring: %m", empty_to_root(crt->cgroup_path)); - } - /* Set attributes */ cgroup_context_apply(u, target_mask, state); cgroup_xattr_apply(u); diff --git a/src/core/cgroup.h b/src/core/cgroup.h index 32a15d06b13..f1c8c59b83c 100644 --- a/src/core/cgroup.h +++ b/src/core/cgroup.h @@ -407,7 +407,6 @@ void unit_invalidate_cgroup_members_masks(Unit *u); void unit_add_family_to_cgroup_realize_queue(Unit *u); -const char* unit_get_realized_cgroup_path(Unit *u, CGroupMask mask); int unit_default_cgroup_path(const Unit *u, char **ret); int unit_set_cgroup_path(Unit *u, const char *path); int unit_pick_cgroup_path(Unit *u); From ff7f99db30d8860a5081a0eb299b7596fdc1239e Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 7 Apr 2025 04:43:36 +0900 Subject: [PATCH 11/16] core/bpf-devices: drop cgroup v1 support --- src/core/bpf-devices.c | 50 ++++++++---------------------------------- src/core/cgroup.c | 20 +++-------------- 2 files changed, 12 insertions(+), 58 deletions(-) diff --git a/src/core/bpf-devices.c b/src/core/bpf-devices.c index 59d31b83d4a..4393e074e96 100644 --- a/src/core/bpf-devices.c +++ b/src/core/bpf-devices.c @@ -261,11 +261,10 @@ int bpf_devices_supported(void) { static int supported = -1; int r; - /* Checks whether BPF device controller is supported. For this, we check five things: + /* Checks whether BPF device controller is supported. For this, we check two things: * * a) whether we are privileged - * b) whether the unified hierarchy is being used - * c) the BPF implementation in the kernel supports BPF_PROG_TYPE_CGROUP_DEVICE programs, which we require + * b) the BPF implementation in the kernel supports BPF_PROG_TYPE_CGROUP_DEVICE programs, which we require */ if (supported >= 0) @@ -276,14 +275,6 @@ int bpf_devices_supported(void) { return supported = 0; } - r = cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER); - if (r < 0) - return log_error_errno(r, "Can't determine whether the unified hierarchy is used: %m"); - if (r == 0) { - log_debug("Not running with unified cgroups, BPF device control is not supported."); - return supported = 0; - } - r = bpf_program_new(BPF_PROG_TYPE_CGROUP_DEVICE, "sd_devices", &program); if (r < 0) { log_debug_errno(r, "Can't allocate CGROUP DEVICE BPF program, BPF device control is not supported: %m"); @@ -315,38 +306,15 @@ static int allow_list_device_pattern( assert(IN_SET(type, 'b', 'c')); - if (cg_all_unified() > 0) { - if (!prog) - return 0; + if (!prog) + return 0; - if (major != UINT_MAX && minor != UINT_MAX) - return bpf_prog_allow_list_device(prog, type, major, minor, p); - else if (major != UINT_MAX) - return bpf_prog_allow_list_major(prog, type, major, p); - else - return bpf_prog_allow_list_class(prog, type, p); + if (major != UINT_MAX && minor != UINT_MAX) + return bpf_prog_allow_list_device(prog, type, major, minor, p); + if (major != UINT_MAX) + return bpf_prog_allow_list_major(prog, type, major, p); - } else { - char buf[2+DECIMAL_STR_MAX(unsigned)*2+2+4]; - int r; - - if (major != UINT_MAX && minor != UINT_MAX) - xsprintf(buf, "%c %u:%u %s", type, major, minor, cgroup_device_permissions_to_string(p)); - else if (major != UINT_MAX) - xsprintf(buf, "%c %u:* %s", type, major, cgroup_device_permissions_to_string(p)); - else - xsprintf(buf, "%c *:* %s", type, cgroup_device_permissions_to_string(p)); - - /* Changing the devices list of a populated cgroup might result in EINVAL, hence ignore - * EINVAL here. */ - - r = cg_set_attribute("devices", path, "devices.allow", buf); - if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EINVAL, -EACCES, -EPERM) ? LOG_DEBUG : LOG_WARNING, - r, "Failed to set devices.allow on %s: %m", path); - - return r; - } + return bpf_prog_allow_list_class(prog, type, p); } int bpf_devices_allow_list_device( diff --git a/src/core/cgroup.c b/src/core/cgroup.c index da7c816338e..566054be837 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -1645,23 +1645,9 @@ static int cgroup_apply_devices(Unit *u) { policy = c->device_policy; - if (cg_all_unified() > 0) { - r = bpf_devices_cgroup_init(&prog, policy, c->device_allow); - if (r < 0) - return log_unit_warning_errno(u, r, "Failed to initialize device control bpf program: %m"); - - } else { - /* Changing the devices list of a populated cgroup might result in EINVAL, hence ignore - * EINVAL here. */ - - if (c->device_allow || policy != CGROUP_DEVICE_POLICY_AUTO) - r = cg_set_attribute("devices", crt->cgroup_path, "devices.deny", "a"); - else - r = cg_set_attribute("devices", crt->cgroup_path, "devices.allow", "a"); - if (r < 0) - log_unit_full_errno(u, IN_SET(r, -ENOENT, -EROFS, -EINVAL, -EACCES, -EPERM) ? LOG_DEBUG : LOG_WARNING, r, - "Failed to reset devices.allow/devices.deny: %m"); - } + r = bpf_devices_cgroup_init(&prog, policy, c->device_allow); + if (r < 0) + return log_unit_warning_errno(u, r, "Failed to initialize device control bpf program: %m"); bool allow_list_static = policy == CGROUP_DEVICE_POLICY_CLOSED || (policy == CGROUP_DEVICE_POLICY_AUTO && c->device_allow); From 3fcb98cbff0a5be8bf7c5deda6c1f7e8a31699bd Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 8 Apr 2025 17:37:11 +0900 Subject: [PATCH 12/16] core/bpf-foreign: drop unnecessary check for cgroup v1 --- src/core/bpf-foreign.h | 4 ---- src/core/cgroup.c | 8 ++------ src/core/dbus-cgroup.c | 11 ----------- 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/core/bpf-foreign.h b/src/core/bpf-foreign.h index e387b1b1d38..c97be7c72f4 100644 --- a/src/core/bpf-foreign.h +++ b/src/core/bpf-foreign.h @@ -4,10 +4,6 @@ #include "unit.h" -static inline int bpf_foreign_supported(void) { - return cg_all_unified(); -} - /* * Attach cgroup-bpf programs foreign to systemd, i.e. loaded to the kernel by an entity * external to systemd. diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 566054be837..6aa9f1fc3e7 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -3542,12 +3542,8 @@ static int cg_bpf_mask_supported(CGroupMask *ret) { if (r > 0) mask |= CGROUP_MASK_BPF_DEVICES; - /* BPF pinned prog */ - r = bpf_foreign_supported(); - if (r < 0) - return r; - if (r > 0) - mask |= CGROUP_MASK_BPF_FOREIGN; + /* BPF pinned prog (always supported by cgroup v2) */ + mask |= CGROUP_MASK_BPF_FOREIGN; /* BPF-based bind{4|6} hooks */ r = bpf_socket_bind_supported(); diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 2be7dfaa295..882c916c102 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -714,17 +714,6 @@ static int bus_cgroup_set_transient_property( return r; unit_write_setting(u, flags, name, buf); - - if (c->bpf_foreign_programs) { - r = bpf_foreign_supported(); - if (r < 0) - return r; - if (r == 0) - log_full(LOG_DEBUG, - "Transient unit %s configures a BPF program pinned to BPF " - "filesystem, but the local system does not support that.\n" - "Starting this unit will fail!", u->id); - } } return 1; From 3988e2489aaf30034e09918890f688780c154af7 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 16 Apr 2025 03:39:24 +0900 Subject: [PATCH 13/16] core: drop several more cgroup version check --- src/core/bpf-firewall.c | 11 ----------- src/core/bpf-util.c | 11 ----------- src/core/cgroup.c | 17 ----------------- src/core/exec-invoke.c | 2 +- src/core/execute.c | 2 +- src/core/service.c | 3 --- src/core/unit.c | 14 +------------- 7 files changed, 3 insertions(+), 57 deletions(-) diff --git a/src/core/bpf-firewall.c b/src/core/bpf-firewall.c index 26f50500cef..69000c1389f 100644 --- a/src/core/bpf-firewall.c +++ b/src/core/bpf-firewall.c @@ -845,23 +845,12 @@ int bpf_firewall_supported(void) { /* Checks whether BPF firewalling is supported. For this, we check the following things: * - * - whether the unified hierarchy is being used * - the BPF implementation in the kernel supports BPF_PROG_TYPE_CGROUP_SKB programs, which we require * - the BPF implementation in the kernel supports the BPF_PROG_DETACH call, which we require */ if (supported >= 0) return supported; - r = cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER); - if (r < 0) - return log_error_errno(r, "bpf-firewall: Can't determine whether the unified hierarchy is used: %m"); - if (r == 0) { - bpf_firewall_unsupported_reason = - log_debug_errno(SYNTHETIC_ERRNO(EUCLEAN), - "bpf-firewall: Not running with unified cgroup hierarchy, BPF firewalling is not supported."); - return supported = BPF_FIREWALL_UNSUPPORTED; - } - /* prog_name is NULL since it is supported only starting from v4.15 kernel. */ r = bpf_program_new(BPF_PROG_TYPE_CGROUP_SKB, NULL, &program); if (r < 0) { diff --git a/src/core/bpf-util.c b/src/core/bpf-util.c index b337ba9afbd..2c07a402cb9 100644 --- a/src/core/bpf-util.c +++ b/src/core/bpf-util.c @@ -13,17 +13,6 @@ bool cgroup_bpf_supported(void) { if (supported >= 0) return supported; - r = cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER); - if (r < 0) { - log_warning_errno(r, "Can't determine whether the unified hierarchy is used: %m"); - return (supported = false); - } - - if (r == 0) { - log_info("Not running with unified cgroup hierarchy, disabling cgroup BPF features."); - return (supported = false); - } - r = dlopen_bpf(); if (r < 0) { log_full_errno(in_initrd() ? LOG_DEBUG : LOG_INFO, diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 6aa9f1fc3e7..e08652c76f3 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -1586,9 +1586,6 @@ void unit_modify_nft_set(Unit *u, bool add) { if (!UNIT_HAS_CGROUP_CONTEXT(u)) return; - if (cg_all_unified() <= 0) - return; - CGroupRuntime *crt = unit_get_cgroup_runtime(u); if (!crt || crt->cgroup_id == 0) return; @@ -2243,13 +2240,6 @@ int unit_watch_cgroup(Unit *u) { if (crt->cgroup_control_inotify_wd >= 0) return 0; - /* Only applies to the unified hierarchy */ - r = cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER); - if (r < 0) - return log_error_errno(r, "Failed to determine whether the name=systemd hierarchy is unified: %m"); - if (r == 0) - return 0; - /* No point in watch the top-level slice, it's never going to run empty. */ if (unit_has_name(u, SPECIAL_ROOT_SLICE)) return 0; @@ -2310,13 +2300,6 @@ int unit_watch_cgroup_memory(Unit *u) { if (crt->cgroup_memory_inotify_wd >= 0) return 0; - /* Only applies to the unified hierarchy */ - r = cg_all_unified(); - if (r < 0) - return log_error_errno(r, "Failed to determine whether the memory controller is unified: %m"); - if (r == 0) - return 0; - r = hashmap_ensure_allocated(&u->manager->cgroup_memory_inotify_wd_unit, &trivial_hash_ops); if (r < 0) return log_oom(); diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index 9f2ce4d42b5..5809d28c8a7 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -5210,7 +5210,7 @@ int exec_invoke( } } - if (cg_unified() > 0 && is_pressure_supported() > 0) { + if (is_pressure_supported() > 0) { if (cgroup_context_want_memory_pressure(cgroup_context)) { r = cg_get_path("memory", params->cgroup_path, "memory.pressure", &memory_pressure_path); if (r < 0) { diff --git a/src/core/execute.c b/src/core/execute.c index dade528b8cf..32af8c51abd 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -576,7 +576,7 @@ int exec_spawn( "--log-level", max_log_levels, "--log-target", log_target_to_string(manager_get_executor_log_target(unit->manager))), environ, - cg_unified() > 0 ? subcgroup_path : NULL, + subcgroup_path, &pidref); /* Drop the ambient set again, so no processes other than sd-executore spawned from the manager inherit it. */ diff --git a/src/core/service.c b/src/core/service.c index c64fa06335e..b835af1f3aa 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -729,9 +729,6 @@ static int service_verify(Service *s) { if (s->type == SERVICE_SIMPLE && s->exec_command[SERVICE_EXEC_START_POST] && exec_context_has_credentials(&s->exec_context)) log_unit_warning(UNIT(s), "Service uses a combination of Type=simple, ExecStartPost=, and credentials. This could lead to race conditions. Continuing."); - if (s->exit_type == SERVICE_EXIT_CGROUP && cg_unified() < CGROUP_UNIFIED_SYSTEMD) - log_unit_warning(UNIT(s), "Service has ExitType=cgroup set, but we are running with legacy cgroups v1, which might not work correctly. Continuing."); - if (s->restart_max_delay_usec == USEC_INFINITY && s->restart_steps > 0) log_unit_warning(UNIT(s), "Service has RestartSteps= but no RestartMaxDelaySec= setting. Ignoring."); diff --git a/src/core/unit.c b/src/core/unit.c index fa283a8b04a..849ae46d074 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1571,9 +1571,6 @@ static int unit_add_oomd_dependencies(Unit *u) { if (!wants_oomd) return 0; - if (!cg_all_unified()) - return 0; - r = cg_mask_supported(&mask); if (r < 0) return log_debug_errno(r, "Failed to determine supported controllers: %m"); @@ -4808,16 +4805,7 @@ int unit_kill_context(Unit *u, KillOperation k) { } else if (r > 0) { - /* FIXME: For now, on the legacy hierarchy, we will not wait for the cgroup members to die if - * we are running in a container or if this is a delegation unit, simply because cgroup - * notification is unreliable in these cases. It doesn't work at all in containers, and outside - * of containers it can be confused easily by left-over directories in the cgroup — which - * however should not exist in non-delegated units. On the unified hierarchy that's different, - * there we get proper events. Hence rely on them. */ - - if (cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER) > 0 || - (detect_container() == 0 && !unit_cgroup_delegate(u))) - wait_for_exit = true; + wait_for_exit = true; if (send_sighup) { r = unit_pid_set(u, &pid_set); From c35a5857637fef063dda6e9acdfa0a215dd07303 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 7 Apr 2025 03:47:16 +0900 Subject: [PATCH 14/16] cgroup-setup: drop cgroup v1 support --- src/shared/cgroup-setup.c | 400 +------------------------------------- src/shared/cgroup-setup.h | 11 -- src/test/test-cgroup.c | 11 +- 3 files changed, 10 insertions(+), 412 deletions(-) diff --git a/src/shared/cgroup-setup.c b/src/shared/cgroup-setup.c index 269824dfc22..f2cb3e87938 100644 --- a/src/shared/cgroup-setup.c +++ b/src/shared/cgroup-setup.c @@ -51,52 +51,6 @@ int cg_cpu_weight_parse(const char *s, uint64_t *ret) { return cg_weight_parse(s, ret); } -int cg_cpu_shares_parse(const char *s, uint64_t *ret) { - uint64_t u; - int r; - - assert(s); - assert(ret); - - if (isempty(s)) { - *ret = CGROUP_CPU_SHARES_INVALID; - return 0; - } - - r = safe_atou64(s, &u); - if (r < 0) - return r; - - if (u < CGROUP_CPU_SHARES_MIN || u > CGROUP_CPU_SHARES_MAX) - return -ERANGE; - - *ret = u; - return 0; -} - -int cg_blkio_weight_parse(const char *s, uint64_t *ret) { - uint64_t u; - int r; - - assert(s); - assert(ret); - - if (isempty(s)) { - *ret = CGROUP_BLKIO_WEIGHT_INVALID; - return 0; - } - - r = safe_atou64(s, &u); - if (r < 0) - return r; - - if (u < CGROUP_BLKIO_WEIGHT_MIN || u > CGROUP_BLKIO_WEIGHT_MAX) - return -ERANGE; - - *ret = u; - return 0; -} - static int trim_cb( RecurseDirEvent event, const char *path, @@ -118,7 +72,7 @@ static int trim_cb( int cg_trim(const char *controller, const char *path, bool delete_root) { _cleanup_free_ char *fs = NULL; - int r, q; + int r; assert(controller); @@ -149,12 +103,6 @@ int cg_trim(const char *controller, const char *path, bool delete_root) { RET_GATHER(r, -errno); } - q = cg_hybrid_unified(); - if (q < 0) - return q; - if (q > 0 && streq(controller, SYSTEMD_CGROUP_CONTROLLER)) - (void) cg_trim(SYSTEMD_CGROUP_CONTROLLER_LEGACY, path, delete_root); - return r; } @@ -181,15 +129,6 @@ int cg_create(const char *controller, const char *path) { if (r < 0) return r; - r = cg_hybrid_unified(); - if (r < 0) - return r; - if (r > 0 && streq(controller, SYSTEMD_CGROUP_CONTROLLER)) { - r = cg_create(SYSTEMD_CGROUP_CONTROLLER_LEGACY, path); - if (r < 0) - log_warning_errno(r, "Failed to create compat systemd cgroup '%s', ignoring: %m", path); - } - return 1; } @@ -218,15 +157,6 @@ int cg_attach(const char *controller, const char *path, pid_t pid) { if (r < 0) return r; - r = cg_hybrid_unified(); - if (r < 0) - return r; - if (r > 0 && streq(controller, SYSTEMD_CGROUP_CONTROLLER)) { - r = cg_attach(SYSTEMD_CGROUP_CONTROLLER_LEGACY, path, pid); - if (r < 0) - log_warning_errno(r, "Failed to attach "PID_FMT" to compat systemd cgroup '%s', ignoring: %m", pid, path); - } - return 0; } @@ -244,31 +174,6 @@ int cg_fd_attach(int fd, pid_t pid) { return write_string_file_at(fd, "cgroup.procs", c, WRITE_STRING_FILE_DISABLE_BUFFER); } -int cg_attach_fallback(const char *controller, const char *path, pid_t pid) { - int r; - - assert(controller); - assert(path); - assert(pid >= 0); - - r = cg_attach(controller, path, pid); - if (r < 0) { - char prefix[strlen(path) + 1]; - - /* This didn't work? Then let's try all prefixes of the destination */ - - PATH_FOREACH_PREFIX(prefix, path) { - int q; - - q = cg_attach(controller, prefix, pid); - if (q >= 0) - return q; - } - } - - return r; -} - int cg_create_and_attach(const char *controller, const char *path, pid_t pid) { int r, q; @@ -293,47 +198,25 @@ int cg_set_access( uid_t uid, gid_t gid) { - struct Attribute { + static const struct { const char *name; bool fatal; - }; - - /* cgroup v1, aka legacy/non-unified */ - static const struct Attribute legacy_attributes[] = { - { "cgroup.procs", true }, - { "tasks", false }, - { "cgroup.clone_children", false }, - {}, - }; - - /* cgroup v2, aka unified */ - static const struct Attribute unified_attributes[] = { + } attributes[] = { { "cgroup.procs", true }, { "cgroup.subtree_control", true }, { "cgroup.threads", false }, { "memory.oom.group", false }, { "memory.reclaim", false }, - {}, - }; - - static const struct Attribute* const attributes[] = { - [false] = legacy_attributes, - [true] = unified_attributes, }; _cleanup_free_ char *fs = NULL; - const struct Attribute *i; - int r, unified; + int r; assert(path); if (uid == UID_INVALID && gid == GID_INVALID) return 0; - unified = cg_unified_controller(controller); - if (unified < 0) - return unified; - /* Configure access to the cgroup itself */ r = cg_get_path(controller, path, NULL, &fs); if (r < 0) @@ -344,7 +227,7 @@ int cg_set_access( return r; /* Configure access to the cgroup's attributes */ - for (i = attributes[unified]; i->name; i++) { + FOREACH_ELEMENT(i, attributes) { fs = mfree(fs); r = cg_get_path(controller, path, i->name, &fs); @@ -360,18 +243,6 @@ int cg_set_access( } } - if (streq(controller, SYSTEMD_CGROUP_CONTROLLER)) { - r = cg_hybrid_unified(); - if (r < 0) - return r; - if (r > 0) { - /* Always propagate access mode from unified to legacy controller */ - r = cg_set_access(SYSTEMD_CGROUP_CONTROLLER_LEGACY, path, uid, gid); - if (r < 0) - log_debug_errno(r, "Failed to set access on compatibility systemd cgroup %s, ignoring: %m", path); - } - } - return 0; } @@ -514,108 +385,15 @@ int cg_migrate( } int cg_create_everywhere(CGroupMask supported, CGroupMask mask, const char *path) { - CGroupController c; - CGroupMask done; - bool created; - int r; - - /* This one will create a cgroup in our private tree, but also - * duplicate it in the trees specified in mask, and remove it - * in all others. - * - * Returns 0 if the group already existed in the systemd hierarchy, - * 1 on success, negative otherwise. - */ - - /* First create the cgroup in our own hierarchy. */ - r = cg_create(SYSTEMD_CGROUP_CONTROLLER, path); - if (r < 0) - return r; - created = r; - - /* If we are in the unified hierarchy, we are done now */ - r = cg_all_unified(); - if (r < 0) - return r; - if (r > 0) - return created; - - supported &= CGROUP_MASK_V1; - mask = CGROUP_MASK_EXTEND_JOINED(mask); - done = 0; - - /* Otherwise, do the same in the other hierarchies */ - for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) { - CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c); - const char *n; - - if (!FLAGS_SET(supported, bit)) - continue; - - if (FLAGS_SET(done, bit)) - continue; - - n = cgroup_controller_to_string(c); - if (FLAGS_SET(mask, bit)) - (void) cg_create(n, path); - - done |= CGROUP_MASK_EXTEND_JOINED(bit); - } - - return created; + return cg_create(SYSTEMD_CGROUP_CONTROLLER, path); } int cg_attach_everywhere(CGroupMask supported, const char *path, pid_t pid) { - int r; - - assert(path); - assert(pid >= 0); - - r = cg_attach(SYSTEMD_CGROUP_CONTROLLER, path, pid); - if (r < 0) - return r; - - r = cg_all_unified(); - if (r < 0) - return r; - if (r > 0) - return 0; - - supported &= CGROUP_MASK_V1; - CGroupMask done = 0; - - for (CGroupController c = 0; c < _CGROUP_CONTROLLER_MAX; c++) { - CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c); - - if (!FLAGS_SET(supported, bit)) - continue; - - if (FLAGS_SET(done, bit)) - continue; - - (void) cg_attach_fallback(cgroup_controller_to_string(c), path, pid); - done |= CGROUP_MASK_EXTEND_JOINED(bit); - } - - return 0; + return cg_attach(SYSTEMD_CGROUP_CONTROLLER, path, pid); } int cg_trim_everywhere(CGroupMask supported, const char *path, bool delete_root) { - int r, q; - - assert(path); - - r = cg_trim(SYSTEMD_CGROUP_CONTROLLER, path, delete_root); - if (r < 0) - return r; - - q = cg_all_unified(); - if (q < 0) - return q; - if (q > 0) - return r; - - return cg_trim_v1_controllers(supported, _CGROUP_MASK_ALL, path, delete_root); + return cg_trim(SYSTEMD_CGROUP_CONTROLLER, path, delete_root); } int cg_enable_everywhere( @@ -638,26 +416,6 @@ int cg_enable_everywhere( return 0; } - r = cg_all_unified(); - if (r < 0) - return r; - if (r == 0) { - /* On the legacy hierarchy there's no concept of "enabling" controllers in cgroups defined. Let's claim - * complete success right away. (If you wonder why we return the full mask here, rather than zero: the - * caller tends to use the returned mask later on to compare if all controllers where properly joined, - * and if not requeues realization. This use is the primary purpose of the return value, hence let's - * minimize surprises here and reduce triggers for re-realization by always saying we fully - * succeeded.) */ - if (ret_result_mask) - *ret_result_mask = mask & supported & CGROUP_MASK_V2; /* If you wonder why we mask this with - * CGROUP_MASK_V2: The 'supported' mask - * might contain pure-V1 or BPF - * controllers, and we never want to - * claim that we could enable those with - * cgroup.subtree_control */ - return 0; - } - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, p, "cgroup.subtree_control", &fs); if (r < 0) return r; @@ -726,148 +484,6 @@ int cg_enable_everywhere( return 0; } -int cg_migrate_recursive( - const char *cfrom, - const char *pfrom, - const char *cto, - const char *pto, - CGroupFlags flags) { - - _cleanup_closedir_ DIR *d = NULL; - int r, ret = 0; - char *fn; - - assert(cfrom); - assert(pfrom); - assert(cto); - assert(pto); - - ret = cg_migrate(cfrom, pfrom, cto, pto, flags); - - r = cg_enumerate_subgroups(cfrom, pfrom, &d); - if (r < 0) { - if (ret >= 0 && r != -ENOENT) - return r; - - return ret; - } - - while ((r = cg_read_subgroup(d, &fn)) > 0) { - _cleanup_free_ char *p = NULL; - - p = path_join(empty_to_root(pfrom), fn); - free(fn); - if (!p) - return -ENOMEM; - - r = cg_migrate_recursive(cfrom, p, cto, pto, flags); - if (r != 0 && ret >= 0) - ret = r; - } - - if (r < 0 && ret >= 0) - ret = r; - - return ret; -} - -int cg_migrate_recursive_fallback( - const char *cfrom, - const char *pfrom, - const char *cto, - const char *pto, - CGroupFlags flags) { - - int r; - - assert(cfrom); - assert(pfrom); - assert(cto); - assert(pto); - - r = cg_migrate_recursive(cfrom, pfrom, cto, pto, flags); - if (r < 0) { - char prefix[strlen(pto) + 1]; - - /* This didn't work? Then let's try all prefixes of the destination */ - - PATH_FOREACH_PREFIX(prefix, pto) { - int q; - - q = cg_migrate_recursive(cfrom, pfrom, cto, prefix, flags); - if (q >= 0) - return q; - } - } - - return r; -} - -int cg_migrate_v1_controllers(CGroupMask supported, CGroupMask mask, const char *from, cg_migrate_callback_t to_callback, void *userdata) { - CGroupController c; - CGroupMask done; - int r = 0, q; - - assert(to_callback); - - supported &= CGROUP_MASK_V1; - mask = CGROUP_MASK_EXTEND_JOINED(mask); - done = 0; - - for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) { - CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c); - const char *to = NULL; - - if (!FLAGS_SET(supported, bit)) - continue; - - if (FLAGS_SET(done, bit)) - continue; - - if (!FLAGS_SET(mask, bit)) - continue; - - to = to_callback(bit, userdata); - - /* Remember first error and try continuing */ - q = cg_migrate_recursive_fallback(SYSTEMD_CGROUP_CONTROLLER, from, cgroup_controller_to_string(c), to, 0); - r = (r < 0) ? r : q; - - done |= CGROUP_MASK_EXTEND_JOINED(bit); - } - - return r; -} - -int cg_trim_v1_controllers(CGroupMask supported, CGroupMask mask, const char *path, bool delete_root) { - CGroupController c; - CGroupMask done; - int r = 0, q; - - supported &= CGROUP_MASK_V1; - mask = CGROUP_MASK_EXTEND_JOINED(mask); - done = 0; - - for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) { - CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c); - - if (!FLAGS_SET(supported, bit)) - continue; - - if (FLAGS_SET(done, bit)) - continue; - - if (FLAGS_SET(mask, bit)) { - /* Remember first error and try continuing */ - q = cg_trim(cgroup_controller_to_string(c), path, delete_root); - r = (r < 0) ? r : q; - } - done |= CGROUP_MASK_EXTEND_JOINED(bit); - } - - return r; -} - int cg_has_legacy(void) { struct statfs fs; diff --git a/src/shared/cgroup-setup.h b/src/shared/cgroup-setup.h index b20de46894c..1427ccd2e28 100644 --- a/src/shared/cgroup-setup.h +++ b/src/shared/cgroup-setup.h @@ -9,15 +9,12 @@ int cg_weight_parse(const char *s, uint64_t *ret); int cg_cpu_weight_parse(const char *s, uint64_t *ret); -int cg_cpu_shares_parse(const char *s, uint64_t *ret); -int cg_blkio_weight_parse(const char *s, uint64_t *ret); int cg_trim(const char *controller, const char *path, bool delete_root); int cg_create(const char *controller, const char *path); int cg_attach(const char *controller, const char *path, pid_t pid); int cg_fd_attach(int fd, pid_t pid); -int cg_attach_fallback(const char *controller, const char *path, pid_t pid); int cg_create_and_attach(const char *controller, const char *path, pid_t pid); int cg_set_access(const char *controller, const char *path, uid_t uid, gid_t gid); @@ -30,12 +27,4 @@ int cg_enable_everywhere(CGroupMask supported, CGroupMask mask, const char *p, C int cg_migrate(const char *cfrom, const char *pfrom, const char *cto, const char *pto, CGroupFlags flags); -typedef const char* (*cg_migrate_callback_t)(CGroupMask mask, void *userdata); - -/* CGroup V1 specific */ -int cg_migrate_recursive(const char *cfrom, const char *pfrom, const char *cto, const char *pto, CGroupFlags flags); -int cg_migrate_recursive_fallback(const char *cfrom, const char *pfrom, const char *cto, const char *pto, CGroupFlags flags); -int cg_migrate_v1_controllers(CGroupMask supported, CGroupMask mask, const char *from, cg_migrate_callback_t to_callback, void *userdata); -int cg_trim_v1_controllers(CGroupMask supported, CGroupMask mask, const char *path, bool delete_root); - int cg_has_legacy(void); diff --git a/src/test/test-cgroup.c b/src/test/test-cgroup.c index dd7d2c578b4..e4fc5d5c62f 100644 --- a/src/test/test-cgroup.c +++ b/src/test/test-cgroup.c @@ -114,15 +114,8 @@ TEST(cg_create) { ASSERT_OK_ZERO(cg_kill_recursive(test_a, 0, 0, NULL, NULL, NULL)); ASSERT_OK_POSITIVE(cg_kill_recursive(test_b, 0, 0, NULL, NULL, NULL)); - ASSERT_OK_POSITIVE(cg_migrate_recursive(SYSTEMD_CGROUP_CONTROLLER, test_b, SYSTEMD_CGROUP_CONTROLLER, test_a, 0)); - - ASSERT_OK_ZERO(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, test_a)); - ASSERT_OK_POSITIVE(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, test_b)); - - ASSERT_OK_POSITIVE(cg_kill_recursive(test_a, 0, 0, NULL, NULL, NULL)); - ASSERT_OK_ZERO(cg_kill_recursive(test_b, 0, 0, NULL, NULL, NULL)); - - ASSERT_OK(cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_b, true)); + ASSERT_OK(cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_a, true)); + ASSERT_ERROR(cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_b, true), EBUSY); } TEST(id) { From 188286eec6b3af2a13c2ccd86038f74e3d5da72f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 7 Apr 2025 04:25:32 +0900 Subject: [PATCH 15/16] cgroup-setup: drop unnecessary controller argument This also removes unnecessary cg_{create,attach,trim}_everywhere(), and rename cg_enable_everywhere() -> cg_enable(). --- src/core/cgroup.c | 16 +++++----- src/core/exec-invoke.c | 6 ++-- src/core/execute.c | 4 +-- src/core/scope.c | 2 +- src/core/unit.c | 2 +- src/nspawn/nspawn-cgroup.c | 8 ++--- src/oom/test-oomd-util.c | 6 ++-- src/shared/cgroup-setup.c | 62 ++++++++++++------------------------- src/shared/cgroup-setup.h | 19 +++++------- src/shared/tests.c | 6 +--- src/shutdown/shutdown.c | 2 +- src/test/test-bpf-devices.c | 3 +- src/test/test-cgroup.c | 22 ++++++------- 13 files changed, 63 insertions(+), 95 deletions(-) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index e08652c76f3..30929ef5ebc 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -2379,7 +2379,7 @@ static int unit_update_cgroup( CGroupRuntime *crt = ASSERT_PTR(unit_get_cgroup_runtime(u)); /* First, create our own group */ - r = cg_create_everywhere(u->manager->cgroup_supported, target_mask, crt->cgroup_path); + r = cg_create(crt->cgroup_path); if (r < 0) return log_unit_error_errno(u, r, "Failed to create cgroup %s: %m", empty_to_root(crt->cgroup_path)); created = r; @@ -2405,7 +2405,7 @@ static int unit_update_cgroup( CGroupMask result_mask = 0; /* Enable all controllers we need */ - r = cg_enable_everywhere(u->manager->cgroup_supported, enable_mask, crt->cgroup_path, &result_mask); + r = cg_enable(u->manager->cgroup_supported, enable_mask, crt->cgroup_path, &result_mask); if (r < 0) log_unit_warning_errno(u, r, "Failed to enable/disable controllers on cgroup %s, ignoring: %m", empty_to_root(crt->cgroup_path)); @@ -2515,7 +2515,7 @@ int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path) { continue; } - r = cg_attach(SYSTEMD_CGROUP_CONTROLLER, p, pid->pid); + r = cg_attach(p, pid->pid); if (r < 0) { bool again = MANAGER_IS_USER(u->manager) && ERRNO_IS_NEG_PRIVILEGE(r); @@ -2590,7 +2590,7 @@ int unit_remove_subcgroup(Unit *u, const char *suffix_path) { log_unit_debug(u, "Removing subcgroup '%s'...", d); - r = cg_trim_everywhere(u->manager->cgroup_supported, d, delete_root); + r = cg_trim(d, delete_root); if (r < 0) return log_unit_debug_errno(u, r, "Failed to fully %s cgroup '%s': %m", delete_root ? "remove" : "trim", d); @@ -3113,7 +3113,7 @@ void unit_prune_cgroup(Unit *u) { is_root_slice = unit_has_name(u, SPECIAL_ROOT_SLICE); - r = cg_trim_everywhere(u->manager->cgroup_supported, crt->cgroup_path, !is_root_slice); + r = cg_trim(crt->cgroup_path, !is_root_slice); if (r < 0) { int k = unit_prune_cgroup_via_bus(u); @@ -3614,10 +3614,10 @@ int manager_setup_cgroup(Manager *m) { /* 5. Make sure we are in the special "init.scope" unit in the root slice. */ const char *scope_path = strjoina(m->cgroup_root, "/" SPECIAL_INIT_SCOPE); - r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, scope_path, /* pid = */ 0); + r = cg_create_and_attach(scope_path, /* pid = */ 0); if (r >= 0) { /* Also, move all other userspace processes remaining in the root cgroup into that scope. */ - r = cg_migrate(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_root, SYSTEMD_CGROUP_CONTROLLER, scope_path, 0); + r = cg_migrate(m->cgroup_root, scope_path, 0); if (r < 0) log_warning_errno(r, "Couldn't move remaining userspace processes, ignoring: %m"); @@ -3650,7 +3650,7 @@ void manager_shutdown_cgroup(Manager *m, bool delete) { /* We can't really delete the group, since we are in it. But * let's trim it. */ if (delete && m->cgroup_root && !FLAGS_SET(m->test_run_flags, MANAGER_TEST_RUN_MINIMAL)) - (void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_root, false); + (void) cg_trim(m->cgroup_root, false); m->cgroup_empty_event_source = sd_event_source_disable_unref(m->cgroup_empty_event_source); diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index 5809d28c8a7..ef129eb770d 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -4967,7 +4967,7 @@ int exec_invoke( return log_exec_error_errno(context, params, r, "Failed to acquire cgroup path: %m"); } - r = cg_attach_everywhere(params->cgroup_supported, p, 0); + r = cg_attach(p, 0); if (r == -EUCLEAN) { *exit_status = EXIT_CGROUP; return log_exec_error_errno(context, params, r, @@ -5190,7 +5190,7 @@ int exec_invoke( if (params->flags & EXEC_CGROUP_DELEGATE) { _cleanup_free_ char *p = NULL; - r = cg_set_access(SYSTEMD_CGROUP_CONTROLLER, params->cgroup_path, uid, gid); + r = cg_set_access(params->cgroup_path, uid, gid); if (r < 0) { *exit_status = EXIT_CGROUP; return log_exec_error_errno(context, params, r, "Failed to adjust control group access: %m"); @@ -5202,7 +5202,7 @@ int exec_invoke( return log_exec_error_errno(context, params, r, "Failed to acquire cgroup path: %m"); } if (r > 0) { - r = cg_set_access_recursive(SYSTEMD_CGROUP_CONTROLLER, p, uid, gid); + r = cg_set_access_recursive(p, uid, gid); if (r < 0) { *exit_status = EXIT_CGROUP; return log_exec_error_errno(context, params, r, "Failed to adjust control subgroup access: %m"); diff --git a/src/core/execute.c b/src/core/execute.c index 32af8c51abd..6f4baa1fbfd 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -508,7 +508,7 @@ int exec_spawn( /* If there's a subcgroup, then let's create it here now (the main cgroup was already * realized by the unit logic) */ - r = cg_create(SYSTEMD_CGROUP_CONTROLLER, subcgroup_path); + r = cg_create(subcgroup_path); if (r < 0) return log_unit_error_errno(unit, r, "Failed to create subcgroup '%s': %m", subcgroup_path); } @@ -593,7 +593,7 @@ int exec_spawn( * executed outside of the cgroup) and in the parent (so that we can be sure that when we kill the cgroup the * process will be killed too). */ if (r == 0 && subcgroup_path) - (void) cg_attach(SYSTEMD_CGROUP_CONTROLLER, subcgroup_path, pidref.pid); + (void) cg_attach(subcgroup_path, pidref.pid); /* r > 0: Already in the right cgroup thanks to CLONE_INTO_CGROUP */ log_unit_debug(unit, "Forked %s as " PID_FMT " (%s CLONE_INTO_CGROUP)", diff --git a/src/core/scope.c b/src/core/scope.c index 40fb41e541a..208716ea074 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -371,7 +371,7 @@ static int scope_enter_start_chown(Scope *s) { } } - r = cg_set_access(SYSTEMD_CGROUP_CONTROLLER, s->cgroup_runtime->cgroup_path, uid, gid); + r = cg_set_access(s->cgroup_runtime->cgroup_path, uid, gid); if (r < 0) { log_unit_error_errno(UNIT(s), r, "Failed to adjust control group access: %m"); _exit(EXIT_CGROUP); diff --git a/src/core/unit.c b/src/core/unit.c index 849ae46d074..75d5921faa4 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -5405,7 +5405,7 @@ int unit_fork_helper_process(Unit *u, const char *name, bool into_cgroup, PidRef (void) ignore_signals(SIGPIPE); if (crt && crt->cgroup_path) { - r = cg_attach_everywhere(u->manager->cgroup_supported, crt->cgroup_path, 0); + r = cg_attach(crt->cgroup_path, 0); if (r < 0) { log_unit_error_errno(u, r, "Failed to join unit cgroup %s: %m", empty_to_root(crt->cgroup_path)); _exit(EXIT_CGROUP); diff --git a/src/nspawn/nspawn-cgroup.c b/src/nspawn/nspawn-cgroup.c index cd5da76af4b..9ec6f277b9a 100644 --- a/src/nspawn/nspawn-cgroup.c +++ b/src/nspawn/nspawn-cgroup.c @@ -88,9 +88,9 @@ int create_subcgroup( return log_oom(); if (userns_mode != USER_NAMESPACE_MANAGED) - r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, payload, pid); + r = cg_create_and_attach(payload, pid); else - r = cg_create(SYSTEMD_CGROUP_CONTROLLER, payload); + r = cg_create(payload); if (r < 0) return log_error_errno(r, "Failed to create %s subcgroup: %m", payload); @@ -125,13 +125,13 @@ int create_subcgroup( if (!supervisor) return log_oom(); - r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, supervisor, 0); + r = cg_create_and_attach(supervisor, 0); if (r < 0) return log_error_errno(r, "Failed to create %s subcgroup: %m", supervisor); } /* Try to enable as many controllers as possible for the new payload. */ - (void) cg_enable_everywhere(supported, supported, cgroup, NULL); + (void) cg_enable(supported, supported, cgroup, NULL); return 0; } diff --git a/src/oom/test-oomd-util.c b/src/oom/test-oomd-util.c index 5f007ee35ec..2eca39c2958 100644 --- a/src/oom/test-oomd-util.c +++ b/src/oom/test-oomd-util.c @@ -52,7 +52,7 @@ static void test_oomd_cgroup_kill(void) { * by the test so that pid1 doesn't delete it before we can read the xattrs. */ cgroup = path_join(cgroup_root, "oomdkilltest"); assert_se(cgroup); - assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, cgroup) >= 0); + assert_se(cg_create(cgroup) >= 0); /* If we don't have permissions to set xattrs we're likely in a userns or missing capabilities */ r = cg_set_xattr(cgroup, "user.oomd_test", "test", 4, 0); @@ -65,7 +65,7 @@ static void test_oomd_cgroup_kill(void) { for (int j = 0; j < 2; j++) { pid[j] = fork_and_sleep(5); - assert_se(cg_attach(SYSTEMD_CGROUP_CONTROLLER, cgroup, pid[j]) >= 0); + assert_se(cg_attach(cgroup, pid[j]) >= 0); } r = oomd_cgroup_kill(cgroup, false /* recurse */, false /* dry run */); @@ -477,7 +477,7 @@ static void test_oomd_fetch_cgroup_oom_preference(void) { * owned by the same user. */ if (test_xattrs && !empty_or_root(cgroup)) { ctx = oomd_cgroup_context_free(ctx); - assert_se(cg_set_access(SYSTEMD_CGROUP_CONTROLLER, cgroup, 61183, 0) >= 0); + assert_se(cg_set_access(cgroup, 61183, 0) >= 0); assert_se(oomd_cgroup_context_acquire(cgroup, &ctx) == 0); assert_se(oomd_fetch_cgroup_oom_preference(ctx, NULL) == 0); diff --git a/src/shared/cgroup-setup.c b/src/shared/cgroup-setup.c index f2cb3e87938..f4d93c2cb07 100644 --- a/src/shared/cgroup-setup.c +++ b/src/shared/cgroup-setup.c @@ -70,13 +70,11 @@ static int trim_cb( return RECURSE_DIR_CONTINUE; } -int cg_trim(const char *controller, const char *path, bool delete_root) { +int cg_trim(const char *path, bool delete_root) { _cleanup_free_ char *fs = NULL; int r; - assert(controller); - - r = cg_get_path(controller, path, NULL, &fs); + r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs); if (r < 0) return r; @@ -109,13 +107,11 @@ int cg_trim(const char *controller, const char *path, bool delete_root) { /* Create a cgroup in the hierarchy of controller. * Returns 0 if the group already existed, 1 on success, negative otherwise. */ -int cg_create(const char *controller, const char *path) { +int cg_create(const char *path) { _cleanup_free_ char *fs = NULL; int r; - assert(controller); - - r = cg_get_path_and_check(controller, path, NULL, &fs); + r = cg_get_path_and_check(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs); if (r < 0) return r; @@ -132,16 +128,15 @@ int cg_create(const char *controller, const char *path) { return 1; } -int cg_attach(const char *controller, const char *path, pid_t pid) { +int cg_attach(const char *path, pid_t pid) { _cleanup_free_ char *fs = NULL; char c[DECIMAL_STR_MAX(pid_t) + 2]; int r; - assert(controller); assert(path); assert(pid >= 0); - r = cg_get_path_and_check(controller, path, "cgroup.procs", &fs); + r = cg_get_path_and_check(SYSTEMD_CGROUP_CONTROLLER, path, "cgroup.procs", &fs); if (r < 0) return r; @@ -174,18 +169,18 @@ int cg_fd_attach(int fd, pid_t pid) { return write_string_file_at(fd, "cgroup.procs", c, WRITE_STRING_FILE_DISABLE_BUFFER); } -int cg_create_and_attach(const char *controller, const char *path, pid_t pid) { +int cg_create_and_attach(const char *path, pid_t pid) { int r, q; /* This does not remove the cgroup on failure */ assert(pid >= 0); - r = cg_create(controller, path); + r = cg_create(path); if (r < 0) return r; - q = cg_attach(controller, path, pid); + q = cg_attach(path, pid); if (q < 0) return q; @@ -193,7 +188,6 @@ int cg_create_and_attach(const char *controller, const char *path, pid_t pid) { } int cg_set_access( - const char *controller, const char *path, uid_t uid, gid_t gid) { @@ -218,7 +212,7 @@ int cg_set_access( return 0; /* Configure access to the cgroup itself */ - r = cg_get_path(controller, path, NULL, &fs); + r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs); if (r < 0) return r; @@ -230,7 +224,7 @@ int cg_set_access( FOREACH_ELEMENT(i, attributes) { fs = mfree(fs); - r = cg_get_path(controller, path, i->name, &fs); + r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, i->name, &fs); if (r < 0) return r; @@ -276,7 +270,6 @@ static int access_callback( } int cg_set_access_recursive( - const char *controller, const char *path, uid_t uid, gid_t gid) { @@ -285,7 +278,6 @@ int cg_set_access_recursive( _cleanup_free_ char *fs = NULL; int r; - assert(controller); assert(path); /* A recursive version of cg_set_access(). But note that this one changes ownership of *all* files, @@ -295,7 +287,7 @@ int cg_set_access_recursive( if (!uid_is_valid(uid) && !gid_is_valid(gid)) return 0; - r = cg_get_path(controller, path, NULL, &fs); + r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs); if (r < 0) return r; @@ -323,20 +315,16 @@ int cg_set_access_recursive( } int cg_migrate( - const char *cfrom, - const char *pfrom, - const char *cto, - const char *pto, + const char *from, + const char *to, CGroupFlags flags) { _cleanup_set_free_ Set *s = NULL; bool done; int r, ret = 0; - assert(cfrom); - assert(pfrom); - assert(cto); - assert(pto); + assert(from); + assert(to); do { _cleanup_fclose_ FILE *f = NULL; @@ -344,7 +332,7 @@ int cg_migrate( done = true; - r = cg_enumerate_processes(cfrom, pfrom, &f); + r = cg_enumerate_processes(SYSTEMD_CGROUP_CONTROLLER, from, &f); if (r < 0) return RET_GATHER(ret, r); @@ -364,7 +352,7 @@ int cg_migrate( if (pid_is_kernel_thread(pid) > 0) continue; - r = cg_attach(cto, pto, pid); + r = cg_attach(to, pid); if (r < 0) { if (r != -ESRCH) RET_GATHER(ret, r); @@ -384,19 +372,7 @@ int cg_migrate( return ret; } -int cg_create_everywhere(CGroupMask supported, CGroupMask mask, const char *path) { - return cg_create(SYSTEMD_CGROUP_CONTROLLER, path); -} - -int cg_attach_everywhere(CGroupMask supported, const char *path, pid_t pid) { - return cg_attach(SYSTEMD_CGROUP_CONTROLLER, path, pid); -} - -int cg_trim_everywhere(CGroupMask supported, const char *path, bool delete_root) { - return cg_trim(SYSTEMD_CGROUP_CONTROLLER, path, delete_root); -} - -int cg_enable_everywhere( +int cg_enable( CGroupMask supported, CGroupMask mask, const char *p, diff --git a/src/shared/cgroup-setup.h b/src/shared/cgroup-setup.h index 1427ccd2e28..5e654426a6d 100644 --- a/src/shared/cgroup-setup.h +++ b/src/shared/cgroup-setup.h @@ -10,21 +10,18 @@ int cg_weight_parse(const char *s, uint64_t *ret); int cg_cpu_weight_parse(const char *s, uint64_t *ret); -int cg_trim(const char *controller, const char *path, bool delete_root); +int cg_trim(const char *path, bool delete_root); -int cg_create(const char *controller, const char *path); -int cg_attach(const char *controller, const char *path, pid_t pid); +int cg_create(const char *path); +int cg_attach(const char *path, pid_t pid); int cg_fd_attach(int fd, pid_t pid); -int cg_create_and_attach(const char *controller, const char *path, pid_t pid); +int cg_create_and_attach(const char *path, pid_t pid); -int cg_set_access(const char *controller, const char *path, uid_t uid, gid_t gid); -int cg_set_access_recursive(const char *controller, const char *path, uid_t uid, gid_t gid); +int cg_set_access(const char *path, uid_t uid, gid_t gid); +int cg_set_access_recursive(const char *path, uid_t uid, gid_t gid); -int cg_create_everywhere(CGroupMask supported, CGroupMask mask, const char *path); -int cg_attach_everywhere(CGroupMask supported, const char *path, pid_t pid); -int cg_trim_everywhere(CGroupMask supported, const char *path, bool delete_root); -int cg_enable_everywhere(CGroupMask supported, CGroupMask mask, const char *p, CGroupMask *ret_result_mask); +int cg_enable(CGroupMask supported, CGroupMask mask, const char *p, CGroupMask *ret_result_mask); -int cg_migrate(const char *cfrom, const char *pfrom, const char *cto, const char *pto, CGroupFlags flags); +int cg_migrate(const char *from, const char *to, CGroupFlags flags); int cg_has_legacy(void); diff --git a/src/shared/tests.c b/src/shared/tests.c index 50b30ca17d5..06f26a2222a 100644 --- a/src/shared/tests.c +++ b/src/shared/tests.c @@ -306,11 +306,7 @@ static int enter_cgroup(char **ret_cgroup, bool enter_subroot) { /* If this fails, then we don't mind as the later cgroup operations will fail too, and it's fine if * we handle any errors at that point. */ - r = cg_create_everywhere(supported, _CGROUP_MASK_ALL, cgroup_subroot); - if (r < 0) - return r; - - r = cg_attach_everywhere(supported, cgroup_subroot, 0); + r = cg_create_and_attach(cgroup_subroot, 0); if (r < 0) return r; diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c index 1859dbfa80a..9c4eb4582dc 100644 --- a/src/shutdown/shutdown.c +++ b/src/shutdown/shutdown.c @@ -466,7 +466,7 @@ int main(int argc, char *argv[]) { /* Let's trim the cgroup tree on each iteration so that we leave an empty cgroup tree around, * so that container managers get a nice notify event when we are down */ if (cgroup) - (void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, cgroup, false); + (void) cg_trim(cgroup, false); if (need_umount) { log_info("Unmounting file systems."); diff --git a/src/test/test-bpf-devices.c b/src/test/test-bpf-devices.c index ae6be16956b..8b0b744892e 100644 --- a/src/test/test-bpf-devices.c +++ b/src/test/test-bpf-devices.c @@ -299,8 +299,7 @@ int main(int argc, char *argv[]) { ASSERT_OK(path_extract_directory(cgroup, &parent)); ASSERT_OK(cg_mask_supported(&supported)); - r = cg_attach_everywhere(supported, parent, 0); - ASSERT_OK(r); + ASSERT_OK(cg_attach(parent, 0)); return 0; } diff --git a/src/test/test-cgroup.c b/src/test/test-cgroup.c index e4fc5d5c62f..a15b880049c 100644 --- a/src/test/test-cgroup.c +++ b/src/test/test-cgroup.c @@ -63,32 +63,32 @@ TEST(cg_create) { log_info("Paths for test:\n%s\n%s", test_a, test_b); /* Possibly clean up left-overs from aboted previous runs */ - (void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_a, /* delete_root= */ true); - (void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_b, /* delete_root= */ true); + (void) cg_trim(test_a, /* delete_root= */ true); + (void) cg_trim(test_b, /* delete_root= */ true); - r = cg_create(SYSTEMD_CGROUP_CONTROLLER, test_a); + r = cg_create(test_a); if (IN_SET(r, -EPERM, -EACCES, -EROFS)) { log_info_errno(r, "Skipping %s: %m", __func__); return; } ASSERT_OK_EQ(r, 1); - ASSERT_OK_ZERO(cg_create(SYSTEMD_CGROUP_CONTROLLER, test_a)); - ASSERT_OK_EQ(cg_create(SYSTEMD_CGROUP_CONTROLLER, test_b), 1); - ASSERT_OK_EQ(cg_create(SYSTEMD_CGROUP_CONTROLLER, test_c), 1); - ASSERT_OK_ZERO(cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, test_b, 0)); + ASSERT_OK_ZERO(cg_create(test_a)); + ASSERT_OK_EQ(cg_create(test_b), 1); + ASSERT_OK_EQ(cg_create(test_c), 1); + ASSERT_OK_ZERO(cg_create_and_attach(test_b, 0)); ASSERT_OK_ZERO(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path)); ASSERT_STREQ(path, test_b); free(path); - ASSERT_OK_ZERO(cg_attach(SYSTEMD_CGROUP_CONTROLLER, test_a, 0)); + ASSERT_OK_ZERO(cg_attach(test_a, 0)); ASSERT_OK_ZERO(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path)); ASSERT_TRUE(path_equal(path, test_a)); free(path); - ASSERT_OK_EQ(cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, test_d, 0), 1); + ASSERT_OK_EQ(cg_create_and_attach(test_d, 0), 1); ASSERT_OK_ZERO(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path)); ASSERT_TRUE(path_equal(path, test_d)); @@ -114,8 +114,8 @@ TEST(cg_create) { ASSERT_OK_ZERO(cg_kill_recursive(test_a, 0, 0, NULL, NULL, NULL)); ASSERT_OK_POSITIVE(cg_kill_recursive(test_b, 0, 0, NULL, NULL, NULL)); - ASSERT_OK(cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_a, true)); - ASSERT_ERROR(cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_b, true), EBUSY); + ASSERT_OK(cg_trim(test_a, true)); + ASSERT_ERROR(cg_trim(test_b, true), EBUSY); } TEST(id) { From b2b270e1d1b4ddb761dd05f20a1d3853d9067b39 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 15 Apr 2025 06:12:05 +0900 Subject: [PATCH 16/16] cgroup-setup: use path_join() to get path to cgroup attribute We already have the path to the cgroup. Hence, it is not necessary to call cg_get_path() again. --- src/shared/cgroup-setup.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/shared/cgroup-setup.c b/src/shared/cgroup-setup.c index f4d93c2cb07..51f04e8c6b5 100644 --- a/src/shared/cgroup-setup.c +++ b/src/shared/cgroup-setup.c @@ -222,18 +222,16 @@ int cg_set_access( /* Configure access to the cgroup's attributes */ FOREACH_ELEMENT(i, attributes) { - fs = mfree(fs); + _cleanup_free_ char *a = path_join(fs, i->name); + if (!a) + return -ENOMEM; - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, i->name, &fs); - if (r < 0) - return r; - - r = chmod_and_chown(fs, 0644, uid, gid); + r = chmod_and_chown(a, 0644, uid, gid); if (r < 0) { if (i->fatal) return r; - log_debug_errno(r, "Failed to set access on cgroup %s, ignoring: %m", fs); + log_debug_errno(r, "Failed to set access on cgroup %s, ignoring: %m", a); } }