mirror of
https://github.com/systemd/systemd.git
synced 2025-03-31 14:50:15 +03:00
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.
This commit is contained in:
parent
372a5002dc
commit
81504017f4
@ -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 */
|
||||
dn = controller_to_dirname(controller);
|
||||
cc = strjoina("/sys/fs/cgroup/", dn);
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user