mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
cgroup: Return ERR_PTR from cgroup_kn_lock_live()
cgroup_kn_lock_live() returns NULL when the cgroup is dead and the callers translate that into an errno themselves. Return ERR_PTR(-ENODEV) instead and have the callers pass the errno through, so that failures other than a dead cgroup can be reported through the same return value. No functional change. Signed-off-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
parent
22098e3b6f
commit
67499cd07b
|
|
@ -506,8 +506,8 @@ static ssize_t __cgroup1_procs_write(struct kernfs_open_file *of,
|
|||
enum cgroup_attach_lock_mode lock_mode;
|
||||
|
||||
cgrp = cgroup_kn_lock_live(of->kn, false);
|
||||
if (!cgrp)
|
||||
return -ENODEV;
|
||||
if (IS_ERR(cgrp))
|
||||
return PTR_ERR(cgrp);
|
||||
|
||||
task = cgroup_procs_write_start(buf, threadgroup, &lock_mode);
|
||||
ret = PTR_ERR_OR_ZERO(task);
|
||||
|
|
@ -569,8 +569,8 @@ static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
|
|||
return -EPERM;
|
||||
|
||||
cgrp = cgroup_kn_lock_live(of->kn, false);
|
||||
if (!cgrp)
|
||||
return -ENODEV;
|
||||
if (IS_ERR(cgrp))
|
||||
return PTR_ERR(cgrp);
|
||||
spin_lock(&release_agent_path_lock);
|
||||
strscpy(cgrp->root->release_agent_path, strstrip(buf),
|
||||
sizeof(cgrp->root->release_agent_path));
|
||||
|
|
|
|||
|
|
@ -1685,8 +1685,8 @@ void cgroup_kn_unlock(struct kernfs_node *kn)
|
|||
* This helper is to be used by a cgroup kernfs method currently servicing
|
||||
* @kn. It breaks the active protection, performs cgroup locking and
|
||||
* verifies that the associated cgroup is alive. Returns the cgroup if
|
||||
* alive; otherwise, %NULL. A successful return should be undone by a
|
||||
* matching cgroup_kn_unlock() invocation. If @drain_offline is %true, the
|
||||
* alive; otherwise, an ERR_PTR value. A successful return should be undone by
|
||||
* a matching cgroup_kn_unlock() invocation. If @drain_offline is %true, the
|
||||
* cgroup is drained of offlining csses before return.
|
||||
*
|
||||
* Any cgroup kernfs method implementation which requires locking the
|
||||
|
|
@ -1710,7 +1710,7 @@ struct cgroup *cgroup_kn_lock_live(struct kernfs_node *kn, bool drain_offline)
|
|||
* break the active_ref protection.
|
||||
*/
|
||||
if (!cgroup_tryget(cgrp))
|
||||
return NULL;
|
||||
return ERR_PTR(-ENODEV);
|
||||
kernfs_break_active_protection(kn);
|
||||
|
||||
if (drain_offline)
|
||||
|
|
@ -1722,7 +1722,7 @@ struct cgroup *cgroup_kn_lock_live(struct kernfs_node *kn, bool drain_offline)
|
|||
return cgrp;
|
||||
|
||||
cgroup_kn_unlock(kn);
|
||||
return NULL;
|
||||
return ERR_PTR(-ENODEV);
|
||||
}
|
||||
|
||||
static void cgroup_rm_file(struct cgroup *cgrp, const struct cftype *cft)
|
||||
|
|
@ -3650,8 +3650,8 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
|
|||
}
|
||||
|
||||
cgrp = cgroup_kn_lock_live(of->kn, true);
|
||||
if (!cgrp)
|
||||
return -ENODEV;
|
||||
if (IS_ERR(cgrp))
|
||||
return PTR_ERR(cgrp);
|
||||
|
||||
for_each_subsys(ss, ssid) {
|
||||
if (enable & (1 << ssid)) {
|
||||
|
|
@ -3790,8 +3790,8 @@ static ssize_t cgroup_type_write(struct kernfs_open_file *of, char *buf,
|
|||
|
||||
/* drain dying csses before we re-apply (threaded) subtree control */
|
||||
cgrp = cgroup_kn_lock_live(of->kn, true);
|
||||
if (!cgrp)
|
||||
return -ENODEV;
|
||||
if (IS_ERR(cgrp))
|
||||
return PTR_ERR(cgrp);
|
||||
|
||||
/* threaded can only be enabled */
|
||||
ret = cgroup_enable_threaded(cgrp);
|
||||
|
|
@ -3833,8 +3833,8 @@ static ssize_t cgroup_max_descendants_write(struct kernfs_open_file *of,
|
|||
return -ERANGE;
|
||||
|
||||
cgrp = cgroup_kn_lock_live(of->kn, false);
|
||||
if (!cgrp)
|
||||
return -ENODEV;
|
||||
if (IS_ERR(cgrp))
|
||||
return PTR_ERR(cgrp);
|
||||
|
||||
WRITE_ONCE(cgrp->max_descendants, descendants);
|
||||
|
||||
|
|
@ -3876,8 +3876,8 @@ static ssize_t cgroup_max_depth_write(struct kernfs_open_file *of,
|
|||
return -ERANGE;
|
||||
|
||||
cgrp = cgroup_kn_lock_live(of->kn, false);
|
||||
if (!cgrp)
|
||||
return -ENODEV;
|
||||
if (IS_ERR(cgrp))
|
||||
return PTR_ERR(cgrp);
|
||||
|
||||
WRITE_ONCE(cgrp->max_depth, depth);
|
||||
|
||||
|
|
@ -4075,8 +4075,8 @@ static ssize_t pressure_write(struct kernfs_open_file *of, char *buf,
|
|||
ssize_t ret = 0;
|
||||
|
||||
cgrp = cgroup_kn_lock_live(of->kn, false);
|
||||
if (!cgrp)
|
||||
return -ENODEV;
|
||||
if (IS_ERR(cgrp))
|
||||
return PTR_ERR(cgrp);
|
||||
|
||||
ctx = of->priv;
|
||||
if (!ctx) {
|
||||
|
|
@ -4192,8 +4192,8 @@ static ssize_t cgroup_pressure_write(struct kernfs_open_file *of,
|
|||
return -ERANGE;
|
||||
|
||||
cgrp = cgroup_kn_lock_live(of->kn, false);
|
||||
if (!cgrp)
|
||||
return -ENODEV;
|
||||
if (IS_ERR(cgrp))
|
||||
return PTR_ERR(cgrp);
|
||||
|
||||
psi = cgroup_psi(cgrp);
|
||||
if (psi->enabled != enable) {
|
||||
|
|
@ -4268,8 +4268,8 @@ static ssize_t cgroup_freeze_write(struct kernfs_open_file *of,
|
|||
return -ERANGE;
|
||||
|
||||
cgrp = cgroup_kn_lock_live(of->kn, false);
|
||||
if (!cgrp)
|
||||
return -ENODEV;
|
||||
if (IS_ERR(cgrp))
|
||||
return PTR_ERR(cgrp);
|
||||
|
||||
cgroup_freeze(cgrp, freeze);
|
||||
|
||||
|
|
@ -4330,8 +4330,8 @@ static ssize_t cgroup_kill_write(struct kernfs_open_file *of, char *buf,
|
|||
return -ERANGE;
|
||||
|
||||
cgrp = cgroup_kn_lock_live(of->kn, false);
|
||||
if (!cgrp)
|
||||
return -ENODEV;
|
||||
if (IS_ERR(cgrp))
|
||||
return PTR_ERR(cgrp);
|
||||
|
||||
/*
|
||||
* Killing is a process directed operation, i.e. the whole thread-group
|
||||
|
|
@ -5485,8 +5485,8 @@ static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,
|
|||
enum cgroup_attach_lock_mode lock_mode;
|
||||
|
||||
dst_cgrp = cgroup_kn_lock_live(of->kn, false);
|
||||
if (!dst_cgrp)
|
||||
return -ENODEV;
|
||||
if (IS_ERR(dst_cgrp))
|
||||
return PTR_ERR(dst_cgrp);
|
||||
|
||||
task = cgroup_procs_write_start(buf, threadgroup, &lock_mode);
|
||||
ret = PTR_ERR_OR_ZERO(task);
|
||||
|
|
@ -6120,8 +6120,8 @@ int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, umode_t mode)
|
|||
return -EINVAL;
|
||||
|
||||
parent = cgroup_kn_lock_live(parent_kn, false);
|
||||
if (!parent)
|
||||
return -ENODEV;
|
||||
if (IS_ERR(parent))
|
||||
return PTR_ERR(parent);
|
||||
|
||||
if (!cgroup_check_hierarchy_limits(parent)) {
|
||||
ret = -EAGAIN;
|
||||
|
|
@ -6397,7 +6397,7 @@ int cgroup_rmdir(struct kernfs_node *kn)
|
|||
int ret = 0;
|
||||
|
||||
cgrp = cgroup_kn_lock_live(kn, false);
|
||||
if (!cgrp)
|
||||
if (IS_ERR(cgrp))
|
||||
return 0;
|
||||
|
||||
ret = cgroup_destroy_locked(cgrp);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ static int current_css_set_read(struct seq_file *seq, void *v)
|
|||
struct cgroup_subsys_state *css;
|
||||
int i, refcnt;
|
||||
|
||||
if (!cgroup_kn_lock_live(of->kn, false))
|
||||
if (IS_ERR(cgroup_kn_lock_live(of->kn, false)))
|
||||
return -ENODEV;
|
||||
|
||||
spin_lock_irq(&css_set_lock);
|
||||
|
|
@ -206,8 +206,8 @@ static int cgroup_subsys_states_read(struct seq_file *seq, void *v)
|
|||
int i;
|
||||
|
||||
cgrp = cgroup_kn_lock_live(of->kn, false);
|
||||
if (!cgrp)
|
||||
return -ENODEV;
|
||||
if (IS_ERR(cgrp))
|
||||
return PTR_ERR(cgrp);
|
||||
|
||||
for_each_subsys(ss, i) {
|
||||
css = rcu_dereference_check(cgrp->subsys[ss->id], true);
|
||||
|
|
@ -254,8 +254,8 @@ static int cgroup_masks_read(struct seq_file *seq, void *v)
|
|||
struct cgroup *cgrp;
|
||||
|
||||
cgrp = cgroup_kn_lock_live(of->kn, false);
|
||||
if (!cgrp)
|
||||
return -ENODEV;
|
||||
if (IS_ERR(cgrp))
|
||||
return PTR_ERR(cgrp);
|
||||
|
||||
cgroup_masks_read_one(seq, "subtree_control", cgrp->subtree_control);
|
||||
cgroup_masks_read_one(seq, "subtree_ss_mask", cgrp->subtree_ss_mask);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user