diff options
author | Michal Koutný <mkoutny@suse.com> | 2021-01-26 17:07:00 +0100 |
---|---|---|
committer | Michal Koutný <mkoutny@suse.com> | 2021-02-11 11:51:59 +0100 |
commit | 81504017f462db1ef4ce2c1f617535f261fe01cc (patch) | |
tree | 1588abde9d38011bbceadafa835ffa2d8deb2d89 | |
parent | 372a5002dceba319e39b83c9dae3ce6d1c7cfb51 (diff) | |
download | systemd-81504017f462db1ef4ce2c1f617535f261fe01cc.tar.gz |
cgroup: Simplify cg_get_path_and_check
The function controller_is_accessible() doesn't do really much in case
of the unified hierarchy. Move common parts into cg_get_path_and_check
and make controller check v1 specific. This is refactoring only.
-rw-r--r-- | src/basic/cgroup-util.c | 56 |
1 files changed, 22 insertions, 34 deletions
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index bb20a12294..fcab1775bd 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -527,41 +527,16 @@ int cg_get_path(const char *controller, const char *path, const char *suffix, ch return 0; } -static int controller_is_accessible(const char *controller) { - int r; +static int controller_is_v1_accessible(const char *controller) { + const char *cc, *dn; assert(controller); - /* Checks whether a specific controller is accessible, - * i.e. its hierarchy mounted. In the unified hierarchy all - * controllers are considered accessible, except for the named - * hierarchies */ - - if (!cg_controller_is_valid(controller)) - return -EINVAL; - - r = cg_all_unified(); - if (r < 0) - return r; - if (r > 0) { - /* We don't support named hierarchies if we are using - * the unified hierarchy. */ - - if (streq(controller, SYSTEMD_CGROUP_CONTROLLER)) - return 0; - - if (startswith(controller, "name=")) - return -EOPNOTSUPP; - - } else { - const char *cc, *dn; - - dn = controller_to_dirname(controller); - cc = strjoina("/sys/fs/cgroup/", dn); + dn = controller_to_dirname(controller); + cc = strjoina("/sys/fs/cgroup/", dn); - if (laccess(cc, F_OK) < 0) - return -errno; - } + if (laccess(cc, F_OK) < 0) + return -errno; return 0; } @@ -572,10 +547,23 @@ int cg_get_path_and_check(const char *controller, const char *path, const char * assert(controller); assert(fs); - /* Check if the specified controller is actually accessible */ - r = controller_is_accessible(controller); + if (!cg_controller_is_valid(controller)) + return -EINVAL; + + r = cg_all_unified(); if (r < 0) return r; + if (r > 0) { + /* In the unified hierarchy all controllers are considered accessible, + * except for the named hierarchies */ + if (startswith(controller, "name=")) + return -EOPNOTSUPP; + } else { + /* Check if the specified controller is actually accessible */ + r = controller_is_v1_accessible(controller); + if (r < 0) + return r; + } return cg_get_path(controller, path, suffix, fs); } @@ -1909,7 +1897,7 @@ int cg_mask_supported(CGroupMask *ret) { continue; n = cgroup_controller_to_string(c); - if (controller_is_accessible(n) >= 0) + if (controller_is_v1_accessible(n) >= 0) mask |= bit; } } |