Merge branch 'for-4.5-ancestor-test' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup into for-4.5
Signed-off-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
@@ -441,11 +441,6 @@ static bool cgroup_tryget(struct cgroup *cgrp)
|
||||
return css_tryget(&cgrp->self);
|
||||
}
|
||||
|
||||
static void cgroup_put(struct cgroup *cgrp)
|
||||
{
|
||||
css_put(&cgrp->self);
|
||||
}
|
||||
|
||||
struct cgroup_subsys_state *of_css(struct kernfs_open_file *of)
|
||||
{
|
||||
struct cgroup *cgrp = of->kn->parent->priv;
|
||||
@@ -466,25 +461,6 @@ struct cgroup_subsys_state *of_css(struct kernfs_open_file *of)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(of_css);
|
||||
|
||||
/**
|
||||
* cgroup_is_descendant - test ancestry
|
||||
* @cgrp: the cgroup to be tested
|
||||
* @ancestor: possible ancestor of @cgrp
|
||||
*
|
||||
* Test whether @cgrp is a descendant of @ancestor. It also returns %true
|
||||
* if @cgrp == @ancestor. This function is safe to call as long as @cgrp
|
||||
* and @ancestor are accessible.
|
||||
*/
|
||||
bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor)
|
||||
{
|
||||
while (cgrp) {
|
||||
if (cgrp == ancestor)
|
||||
return true;
|
||||
cgrp = cgroup_parent(cgrp);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int notify_on_release(const struct cgroup *cgrp)
|
||||
{
|
||||
return test_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
|
||||
@@ -1912,6 +1888,7 @@ static int cgroup_setup_root(struct cgroup_root *root, unsigned long ss_mask)
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
root_cgrp->id = ret;
|
||||
root_cgrp->ancestor_ids[0] = ret;
|
||||
|
||||
ret = percpu_ref_init(&root_cgrp->self.refcnt, css_release, 0,
|
||||
GFP_KERNEL);
|
||||
@@ -4901,11 +4878,11 @@ err_free_css:
|
||||
static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
|
||||
umode_t mode)
|
||||
{
|
||||
struct cgroup *parent, *cgrp;
|
||||
struct cgroup *parent, *cgrp, *tcgrp;
|
||||
struct cgroup_root *root;
|
||||
struct cgroup_subsys *ss;
|
||||
struct kernfs_node *kn;
|
||||
int ssid, ret;
|
||||
int level, ssid, ret;
|
||||
|
||||
/* Do not accept '\n' to prevent making /proc/<pid>/cgroup unparsable.
|
||||
*/
|
||||
@@ -4916,9 +4893,11 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
|
||||
if (!parent)
|
||||
return -ENODEV;
|
||||
root = parent->root;
|
||||
level = parent->level + 1;
|
||||
|
||||
/* allocate the cgroup and its ID, 0 is reserved for the root */
|
||||
cgrp = kzalloc(sizeof(*cgrp), GFP_KERNEL);
|
||||
cgrp = kzalloc(sizeof(*cgrp) +
|
||||
sizeof(cgrp->ancestor_ids[0]) * (level + 1), GFP_KERNEL);
|
||||
if (!cgrp) {
|
||||
ret = -ENOMEM;
|
||||
goto out_unlock;
|
||||
@@ -4942,6 +4921,10 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
|
||||
|
||||
cgrp->self.parent = &parent->self;
|
||||
cgrp->root = root;
|
||||
cgrp->level = level;
|
||||
|
||||
for (tcgrp = cgrp; tcgrp; tcgrp = cgroup_parent(tcgrp))
|
||||
cgrp->ancestor_ids[tcgrp->level] = tcgrp->id;
|
||||
|
||||
if (notify_on_release(parent))
|
||||
set_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
|
||||
@@ -5805,6 +5788,40 @@ struct cgroup_subsys_state *css_from_id(int id, struct cgroup_subsys *ss)
|
||||
return id > 0 ? idr_find(&ss->css_idr, id) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* cgroup_get_from_path - lookup and get a cgroup from its default hierarchy path
|
||||
* @path: path on the default hierarchy
|
||||
*
|
||||
* Find the cgroup at @path on the default hierarchy, increment its
|
||||
* reference count and return it. Returns pointer to the found cgroup on
|
||||
* success, ERR_PTR(-ENOENT) if @path doens't exist and ERR_PTR(-ENOTDIR)
|
||||
* if @path points to a non-directory.
|
||||
*/
|
||||
struct cgroup *cgroup_get_from_path(const char *path)
|
||||
{
|
||||
struct kernfs_node *kn;
|
||||
struct cgroup *cgrp;
|
||||
|
||||
mutex_lock(&cgroup_mutex);
|
||||
|
||||
kn = kernfs_walk_and_get(cgrp_dfl_root.cgrp.kn, path);
|
||||
if (kn) {
|
||||
if (kernfs_type(kn) == KERNFS_DIR) {
|
||||
cgrp = kn->priv;
|
||||
cgroup_get(cgrp);
|
||||
} else {
|
||||
cgrp = ERR_PTR(-ENOTDIR);
|
||||
}
|
||||
kernfs_put(kn);
|
||||
} else {
|
||||
cgrp = ERR_PTR(-ENOENT);
|
||||
}
|
||||
|
||||
mutex_unlock(&cgroup_mutex);
|
||||
return cgrp;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(cgroup_get_from_path);
|
||||
|
||||
#ifdef CONFIG_CGROUP_DEBUG
|
||||
static struct cgroup_subsys_state *
|
||||
debug_css_alloc(struct cgroup_subsys_state *parent_css)
|
||||
|
Reference in New Issue
Block a user