cgroup: rename ->create/post_create/pre_destroy/destroy() to ->css_alloc/online/offline/free()
Rename cgroup_subsys css lifetime related callbacks to better describe what their roles are. Also, update documentation. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
This commit is contained in:
@@ -876,7 +876,7 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode)
|
||||
* Release the subsystem state objects.
|
||||
*/
|
||||
for_each_subsys(cgrp->root, ss)
|
||||
ss->destroy(cgrp);
|
||||
ss->css_free(cgrp);
|
||||
|
||||
cgrp->root->number_of_cgroups--;
|
||||
mutex_unlock(&cgroup_mutex);
|
||||
@@ -4048,8 +4048,8 @@ static int online_css(struct cgroup_subsys *ss, struct cgroup *cgrp)
|
||||
|
||||
lockdep_assert_held(&cgroup_mutex);
|
||||
|
||||
if (ss->post_create)
|
||||
ret = ss->post_create(cgrp);
|
||||
if (ss->css_online)
|
||||
ret = ss->css_online(cgrp);
|
||||
if (!ret)
|
||||
cgrp->subsys[ss->subsys_id]->flags |= CSS_ONLINE;
|
||||
return ret;
|
||||
@@ -4067,14 +4067,14 @@ static void offline_css(struct cgroup_subsys *ss, struct cgroup *cgrp)
|
||||
return;
|
||||
|
||||
/*
|
||||
* pre_destroy() should be called with cgroup_mutex unlocked. See
|
||||
* css_offline() should be called with cgroup_mutex unlocked. See
|
||||
* 3fa59dfbc3 ("cgroup: fix potential deadlock in pre_destroy") for
|
||||
* details. This temporary unlocking should go away once
|
||||
* cgroup_mutex is unexported from controllers.
|
||||
*/
|
||||
if (ss->pre_destroy) {
|
||||
if (ss->css_offline) {
|
||||
mutex_unlock(&cgroup_mutex);
|
||||
ss->pre_destroy(cgrp);
|
||||
ss->css_offline(cgrp);
|
||||
mutex_lock(&cgroup_mutex);
|
||||
}
|
||||
|
||||
@@ -4136,7 +4136,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
|
||||
for_each_subsys(root, ss) {
|
||||
struct cgroup_subsys_state *css;
|
||||
|
||||
css = ss->create(cgrp);
|
||||
css = ss->css_alloc(cgrp);
|
||||
if (IS_ERR(css)) {
|
||||
err = PTR_ERR(css);
|
||||
goto err_free_all;
|
||||
@@ -4147,7 +4147,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
|
||||
if (err)
|
||||
goto err_free_all;
|
||||
}
|
||||
/* At error, ->destroy() callback has to free assigned ID. */
|
||||
/* At error, ->css_free() callback has to free assigned ID. */
|
||||
if (clone_children(parent) && ss->post_clone)
|
||||
ss->post_clone(cgrp);
|
||||
|
||||
@@ -4201,7 +4201,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
|
||||
err_free_all:
|
||||
for_each_subsys(root, ss) {
|
||||
if (cgrp->subsys[ss->subsys_id])
|
||||
ss->destroy(cgrp);
|
||||
ss->css_free(cgrp);
|
||||
}
|
||||
mutex_unlock(&cgroup_mutex);
|
||||
/* Release the reference count that we took on the superblock */
|
||||
@@ -4381,7 +4381,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)
|
||||
/* Create the top cgroup state for this subsystem */
|
||||
list_add(&ss->sibling, &rootnode.subsys_list);
|
||||
ss->root = &rootnode;
|
||||
css = ss->create(dummytop);
|
||||
css = ss->css_alloc(dummytop);
|
||||
/* We don't handle early failures gracefully */
|
||||
BUG_ON(IS_ERR(css));
|
||||
init_cgroup_css(css, ss, dummytop);
|
||||
@@ -4425,7 +4425,7 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)
|
||||
|
||||
/* check name and function validity */
|
||||
if (ss->name == NULL || strlen(ss->name) > MAX_CGROUP_TYPE_NAMELEN ||
|
||||
ss->create == NULL || ss->destroy == NULL)
|
||||
ss->css_alloc == NULL || ss->css_free == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
/*
|
||||
@@ -4454,10 +4454,11 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)
|
||||
subsys[ss->subsys_id] = ss;
|
||||
|
||||
/*
|
||||
* no ss->create seems to need anything important in the ss struct, so
|
||||
* this can happen first (i.e. before the rootnode attachment).
|
||||
* no ss->css_alloc seems to need anything important in the ss
|
||||
* struct, so this can happen first (i.e. before the rootnode
|
||||
* attachment).
|
||||
*/
|
||||
css = ss->create(dummytop);
|
||||
css = ss->css_alloc(dummytop);
|
||||
if (IS_ERR(css)) {
|
||||
/* failure case - need to deassign the subsys[] slot. */
|
||||
subsys[ss->subsys_id] = NULL;
|
||||
@@ -4577,12 +4578,12 @@ void cgroup_unload_subsys(struct cgroup_subsys *ss)
|
||||
write_unlock(&css_set_lock);
|
||||
|
||||
/*
|
||||
* remove subsystem's css from the dummytop and free it - need to free
|
||||
* before marking as null because ss->destroy needs the cgrp->subsys
|
||||
* pointer to find their state. note that this also takes care of
|
||||
* freeing the css_id.
|
||||
* remove subsystem's css from the dummytop and free it - need to
|
||||
* free before marking as null because ss->css_free needs the
|
||||
* cgrp->subsys pointer to find their state. note that this also
|
||||
* takes care of freeing the css_id.
|
||||
*/
|
||||
ss->destroy(dummytop);
|
||||
ss->css_free(dummytop);
|
||||
dummytop->subsys[ss->subsys_id] = NULL;
|
||||
|
||||
mutex_unlock(&cgroup_mutex);
|
||||
@@ -4626,8 +4627,8 @@ int __init cgroup_init_early(void)
|
||||
|
||||
BUG_ON(!ss->name);
|
||||
BUG_ON(strlen(ss->name) > MAX_CGROUP_TYPE_NAMELEN);
|
||||
BUG_ON(!ss->create);
|
||||
BUG_ON(!ss->destroy);
|
||||
BUG_ON(!ss->css_alloc);
|
||||
BUG_ON(!ss->css_free);
|
||||
if (ss->subsys_id != i) {
|
||||
printk(KERN_ERR "cgroup: Subsys %s id == %d\n",
|
||||
ss->name, ss->subsys_id);
|
||||
@@ -5439,7 +5440,7 @@ struct cgroup_subsys_state *cgroup_css_from_dir(struct file *f, int id)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_CGROUP_DEBUG
|
||||
static struct cgroup_subsys_state *debug_create(struct cgroup *cont)
|
||||
static struct cgroup_subsys_state *debug_css_alloc(struct cgroup *cont)
|
||||
{
|
||||
struct cgroup_subsys_state *css = kzalloc(sizeof(*css), GFP_KERNEL);
|
||||
|
||||
@@ -5449,7 +5450,7 @@ static struct cgroup_subsys_state *debug_create(struct cgroup *cont)
|
||||
return css;
|
||||
}
|
||||
|
||||
static void debug_destroy(struct cgroup *cont)
|
||||
static void debug_css_free(struct cgroup *cont)
|
||||
{
|
||||
kfree(cont->subsys[debug_subsys_id]);
|
||||
}
|
||||
@@ -5578,8 +5579,8 @@ static struct cftype debug_files[] = {
|
||||
|
||||
struct cgroup_subsys debug_subsys = {
|
||||
.name = "debug",
|
||||
.create = debug_create,
|
||||
.destroy = debug_destroy,
|
||||
.css_alloc = debug_css_alloc,
|
||||
.css_free = debug_css_free,
|
||||
.subsys_id = debug_subsys_id,
|
||||
.base_cftypes = debug_files,
|
||||
};
|
||||
|
@@ -92,7 +92,7 @@ static const char *freezer_state_strs(unsigned int state)
|
||||
|
||||
struct cgroup_subsys freezer_subsys;
|
||||
|
||||
static struct cgroup_subsys_state *freezer_create(struct cgroup *cgroup)
|
||||
static struct cgroup_subsys_state *freezer_css_alloc(struct cgroup *cgroup)
|
||||
{
|
||||
struct freezer *freezer;
|
||||
|
||||
@@ -105,14 +105,14 @@ static struct cgroup_subsys_state *freezer_create(struct cgroup *cgroup)
|
||||
}
|
||||
|
||||
/**
|
||||
* freezer_post_create - commit creation of a freezer cgroup
|
||||
* freezer_css_online - commit creation of a freezer cgroup
|
||||
* @cgroup: cgroup being created
|
||||
*
|
||||
* We're committing to creation of @cgroup. Mark it online and inherit
|
||||
* parent's freezing state while holding both parent's and our
|
||||
* freezer->lock.
|
||||
*/
|
||||
static int freezer_post_create(struct cgroup *cgroup)
|
||||
static int freezer_css_online(struct cgroup *cgroup)
|
||||
{
|
||||
struct freezer *freezer = cgroup_freezer(cgroup);
|
||||
struct freezer *parent = parent_freezer(freezer);
|
||||
@@ -141,13 +141,13 @@ static int freezer_post_create(struct cgroup *cgroup)
|
||||
}
|
||||
|
||||
/**
|
||||
* freezer_pre_destroy - initiate destruction of @cgroup
|
||||
* freezer_css_offline - initiate destruction of @cgroup
|
||||
* @cgroup: cgroup being destroyed
|
||||
*
|
||||
* @cgroup is going away. Mark it dead and decrement system_freezing_count
|
||||
* if it was holding one.
|
||||
*/
|
||||
static void freezer_pre_destroy(struct cgroup *cgroup)
|
||||
static void freezer_css_offline(struct cgroup *cgroup)
|
||||
{
|
||||
struct freezer *freezer = cgroup_freezer(cgroup);
|
||||
|
||||
@@ -161,7 +161,7 @@ static void freezer_pre_destroy(struct cgroup *cgroup)
|
||||
spin_unlock_irq(&freezer->lock);
|
||||
}
|
||||
|
||||
static void freezer_destroy(struct cgroup *cgroup)
|
||||
static void freezer_css_free(struct cgroup *cgroup)
|
||||
{
|
||||
kfree(cgroup_freezer(cgroup));
|
||||
}
|
||||
@@ -477,10 +477,10 @@ static struct cftype files[] = {
|
||||
|
||||
struct cgroup_subsys freezer_subsys = {
|
||||
.name = "freezer",
|
||||
.create = freezer_create,
|
||||
.post_create = freezer_post_create,
|
||||
.pre_destroy = freezer_pre_destroy,
|
||||
.destroy = freezer_destroy,
|
||||
.css_alloc = freezer_css_alloc,
|
||||
.css_online = freezer_css_online,
|
||||
.css_offline = freezer_css_offline,
|
||||
.css_free = freezer_css_free,
|
||||
.subsys_id = freezer_subsys_id,
|
||||
.attach = freezer_attach,
|
||||
.fork = freezer_fork,
|
||||
|
@@ -1821,11 +1821,11 @@ static void cpuset_post_clone(struct cgroup *cgroup)
|
||||
}
|
||||
|
||||
/*
|
||||
* cpuset_create - create a cpuset
|
||||
* cpuset_css_alloc - allocate a cpuset css
|
||||
* cont: control group that the new cpuset will be part of
|
||||
*/
|
||||
|
||||
static struct cgroup_subsys_state *cpuset_create(struct cgroup *cont)
|
||||
static struct cgroup_subsys_state *cpuset_css_alloc(struct cgroup *cont)
|
||||
{
|
||||
struct cpuset *cs;
|
||||
struct cpuset *parent;
|
||||
@@ -1864,7 +1864,7 @@ static struct cgroup_subsys_state *cpuset_create(struct cgroup *cont)
|
||||
* will call async_rebuild_sched_domains().
|
||||
*/
|
||||
|
||||
static void cpuset_destroy(struct cgroup *cont)
|
||||
static void cpuset_css_free(struct cgroup *cont)
|
||||
{
|
||||
struct cpuset *cs = cgroup_cs(cont);
|
||||
|
||||
@@ -1878,8 +1878,8 @@ static void cpuset_destroy(struct cgroup *cont)
|
||||
|
||||
struct cgroup_subsys cpuset_subsys = {
|
||||
.name = "cpuset",
|
||||
.create = cpuset_create,
|
||||
.destroy = cpuset_destroy,
|
||||
.css_alloc = cpuset_css_alloc,
|
||||
.css_free = cpuset_css_free,
|
||||
.can_attach = cpuset_can_attach,
|
||||
.attach = cpuset_attach,
|
||||
.post_clone = cpuset_post_clone,
|
||||
|
@@ -7434,7 +7434,7 @@ unlock:
|
||||
device_initcall(perf_event_sysfs_init);
|
||||
|
||||
#ifdef CONFIG_CGROUP_PERF
|
||||
static struct cgroup_subsys_state *perf_cgroup_create(struct cgroup *cont)
|
||||
static struct cgroup_subsys_state *perf_cgroup_css_alloc(struct cgroup *cont)
|
||||
{
|
||||
struct perf_cgroup *jc;
|
||||
|
||||
@@ -7451,7 +7451,7 @@ static struct cgroup_subsys_state *perf_cgroup_create(struct cgroup *cont)
|
||||
return &jc->css;
|
||||
}
|
||||
|
||||
static void perf_cgroup_destroy(struct cgroup *cont)
|
||||
static void perf_cgroup_css_free(struct cgroup *cont)
|
||||
{
|
||||
struct perf_cgroup *jc;
|
||||
jc = container_of(cgroup_subsys_state(cont, perf_subsys_id),
|
||||
@@ -7492,8 +7492,8 @@ static void perf_cgroup_exit(struct cgroup *cgrp, struct cgroup *old_cgrp,
|
||||
struct cgroup_subsys perf_subsys = {
|
||||
.name = "perf_event",
|
||||
.subsys_id = perf_subsys_id,
|
||||
.create = perf_cgroup_create,
|
||||
.destroy = perf_cgroup_destroy,
|
||||
.css_alloc = perf_cgroup_css_alloc,
|
||||
.css_free = perf_cgroup_css_free,
|
||||
.exit = perf_cgroup_exit,
|
||||
.attach = perf_cgroup_attach,
|
||||
|
||||
|
@@ -7468,7 +7468,7 @@ static inline struct task_group *cgroup_tg(struct cgroup *cgrp)
|
||||
struct task_group, css);
|
||||
}
|
||||
|
||||
static struct cgroup_subsys_state *cpu_cgroup_create(struct cgroup *cgrp)
|
||||
static struct cgroup_subsys_state *cpu_cgroup_css_alloc(struct cgroup *cgrp)
|
||||
{
|
||||
struct task_group *tg, *parent;
|
||||
|
||||
@@ -7485,7 +7485,7 @@ static struct cgroup_subsys_state *cpu_cgroup_create(struct cgroup *cgrp)
|
||||
return &tg->css;
|
||||
}
|
||||
|
||||
static void cpu_cgroup_destroy(struct cgroup *cgrp)
|
||||
static void cpu_cgroup_css_free(struct cgroup *cgrp)
|
||||
{
|
||||
struct task_group *tg = cgroup_tg(cgrp);
|
||||
|
||||
@@ -7845,8 +7845,8 @@ static struct cftype cpu_files[] = {
|
||||
|
||||
struct cgroup_subsys cpu_cgroup_subsys = {
|
||||
.name = "cpu",
|
||||
.create = cpu_cgroup_create,
|
||||
.destroy = cpu_cgroup_destroy,
|
||||
.css_alloc = cpu_cgroup_css_alloc,
|
||||
.css_free = cpu_cgroup_css_free,
|
||||
.can_attach = cpu_cgroup_can_attach,
|
||||
.attach = cpu_cgroup_attach,
|
||||
.exit = cpu_cgroup_exit,
|
||||
@@ -7869,7 +7869,7 @@ struct cgroup_subsys cpu_cgroup_subsys = {
|
||||
struct cpuacct root_cpuacct;
|
||||
|
||||
/* create a new cpu accounting group */
|
||||
static struct cgroup_subsys_state *cpuacct_create(struct cgroup *cgrp)
|
||||
static struct cgroup_subsys_state *cpuacct_css_alloc(struct cgroup *cgrp)
|
||||
{
|
||||
struct cpuacct *ca;
|
||||
|
||||
@@ -7899,7 +7899,7 @@ out:
|
||||
}
|
||||
|
||||
/* destroy an existing cpu accounting group */
|
||||
static void cpuacct_destroy(struct cgroup *cgrp)
|
||||
static void cpuacct_css_free(struct cgroup *cgrp)
|
||||
{
|
||||
struct cpuacct *ca = cgroup_ca(cgrp);
|
||||
|
||||
@@ -8070,8 +8070,8 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime)
|
||||
|
||||
struct cgroup_subsys cpuacct_subsys = {
|
||||
.name = "cpuacct",
|
||||
.create = cpuacct_create,
|
||||
.destroy = cpuacct_destroy,
|
||||
.css_alloc = cpuacct_css_alloc,
|
||||
.css_free = cpuacct_css_free,
|
||||
.subsys_id = cpuacct_subsys_id,
|
||||
.base_cftypes = files,
|
||||
};
|
||||
|
Reference in New Issue
Block a user