Commit 2739d3cc authored by Li Zefan's avatar Li Zefan Committed by Tejun Heo

cgroup: fix bogus kernel warnings when cgroup_create() failed

If cgroup_create() failed and cgroup_destroy_locked() is called to
do cleanup, we'll see a bunch of warnings:

cgroup_addrm_files: failed to remove 2MB.limit_in_bytes, err=-2
cgroup_addrm_files: failed to remove 2MB.usage_in_bytes, err=-2
cgroup_addrm_files: failed to remove 2MB.max_usage_in_bytes, err=-2
cgroup_addrm_files: failed to remove 2MB.failcnt, err=-2
cgroup_addrm_files: failed to remove prioidx, err=-2
cgroup_addrm_files: failed to remove ifpriomap, err=-2
...

We failed to remove those files, because cgroup_create() has failed
before creating those cgroup files.

To fix this, we simply don't warn if cgroup_rm_file() can't find the
cft entry.
Signed-off-by: default avatarLi Zefan <lizefan@huawei.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent 130e3695
...@@ -921,13 +921,17 @@ static void remove_dir(struct dentry *d) ...@@ -921,13 +921,17 @@ static void remove_dir(struct dentry *d)
dput(parent); dput(parent);
} }
static int cgroup_rm_file(struct cgroup *cgrp, const struct cftype *cft) static void cgroup_rm_file(struct cgroup *cgrp, const struct cftype *cft)
{ {
struct cfent *cfe; struct cfent *cfe;
lockdep_assert_held(&cgrp->dentry->d_inode->i_mutex); lockdep_assert_held(&cgrp->dentry->d_inode->i_mutex);
lockdep_assert_held(&cgroup_mutex); lockdep_assert_held(&cgroup_mutex);
/*
* If we're doing cleanup due to failure of cgroup_create(),
* the corresponding @cfe may not exist.
*/
list_for_each_entry(cfe, &cgrp->files, node) { list_for_each_entry(cfe, &cgrp->files, node) {
struct dentry *d = cfe->dentry; struct dentry *d = cfe->dentry;
...@@ -940,9 +944,8 @@ static int cgroup_rm_file(struct cgroup *cgrp, const struct cftype *cft) ...@@ -940,9 +944,8 @@ static int cgroup_rm_file(struct cgroup *cgrp, const struct cftype *cft)
list_del_init(&cfe->node); list_del_init(&cfe->node);
dput(d); dput(d);
return 0; break;
} }
return -ENOENT;
} }
/** /**
...@@ -2758,14 +2761,14 @@ static int cgroup_addrm_files(struct cgroup *cgrp, struct cgroup_subsys *subsys, ...@@ -2758,14 +2761,14 @@ static int cgroup_addrm_files(struct cgroup *cgrp, struct cgroup_subsys *subsys,
if ((cft->flags & CFTYPE_ONLY_ON_ROOT) && cgrp->parent) if ((cft->flags & CFTYPE_ONLY_ON_ROOT) && cgrp->parent)
continue; continue;
if (is_add) if (is_add) {
err = cgroup_add_file(cgrp, subsys, cft); err = cgroup_add_file(cgrp, subsys, cft);
else if (err)
err = cgroup_rm_file(cgrp, cft); pr_warn("cgroup_addrm_files: failed to add %s, err=%d\n",
if (err) { cft->name, err);
pr_warning("cgroup_addrm_files: failed to %s %s, err=%d\n",
is_add ? "add" : "remove", cft->name, err);
ret = err; ret = err;
} else {
cgroup_rm_file(cgrp, cft);
} }
} }
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment