/**
* cgroup_css - obtain a cgroup's css for the specified subsystem
* @cgrp: the cgroup of interest
- * @subsys_id: the subsystem of interest
+ * @ss: the subsystem of interest (%NULL returns the dummy_css)
*
- * Return @cgrp's css (cgroup_subsys_state) associated with @subsys_id.
- * This function must be called either under cgroup_mutex or
- * rcu_read_lock() and the caller is responsible for pinning the returned
- * css if it wants to keep accessing it outside the said locks. This
- * function may return %NULL if @cgrp doesn't have @subsys_id enabled.
+ * Return @cgrp's css (cgroup_subsys_state) associated with @ss. This
+ * function must be called either under cgroup_mutex or rcu_read_lock() and
+ * the caller is responsible for pinning the returned css if it wants to
+ * keep accessing it outside the said locks. This function may return
+ * %NULL if @cgrp doesn't have @subsys_id enabled.
*/
static struct cgroup_subsys_state *cgroup_css(struct cgroup *cgrp,
- int subsys_id)
+ struct cgroup_subsys *ss)
{
- return rcu_dereference_check(cgrp->subsys[subsys_id],
- lockdep_is_held(&cgroup_mutex));
+ if (ss)
+ return rcu_dereference_check(cgrp->subsys[ss->subsys_id],
+ lockdep_is_held(&cgroup_mutex));
+ else
+ return &cgrp->dummy_css;
}
/* convenient tests for these bits */
/* Subsystem is in this hierarchy. So we want
* the subsystem state from the new
* cgroup */
- template[i] = cgroup_css(cgrp, i);
+ template[i] = cgroup_css(cgrp, ss);
} else {
/* Subsystem is not in this hierarchy, so we
* don't want to change the subsystem state */
if (bit & added_mask) {
/* We're binding this subsystem to this hierarchy */
- BUG_ON(cgroup_css(cgrp, i));
- BUG_ON(!cgroup_css(cgroup_dummy_top, i));
- BUG_ON(cgroup_css(cgroup_dummy_top, i)->cgroup != cgroup_dummy_top);
+ BUG_ON(cgroup_css(cgrp, ss));
+ BUG_ON(!cgroup_css(cgroup_dummy_top, ss));
+ BUG_ON(cgroup_css(cgroup_dummy_top, ss)->cgroup != cgroup_dummy_top);
rcu_assign_pointer(cgrp->subsys[i],
- cgroup_css(cgroup_dummy_top, i));
- cgroup_css(cgrp, i)->cgroup = cgrp;
+ cgroup_css(cgroup_dummy_top, ss));
+ cgroup_css(cgrp, ss)->cgroup = cgrp;
list_move(&ss->sibling, &root->subsys_list);
ss->root = root;
if (ss->bind)
- ss->bind(cgroup_css(cgrp, i));
+ ss->bind(cgroup_css(cgrp, ss));
/* refcount was already taken, and we're keeping it */
root->subsys_mask |= bit;
} else if (bit & removed_mask) {
/* We're removing this subsystem */
- BUG_ON(cgroup_css(cgrp, i) != cgroup_css(cgroup_dummy_top, i));
- BUG_ON(cgroup_css(cgrp, i)->cgroup != cgrp);
+ BUG_ON(cgroup_css(cgrp, ss) != cgroup_css(cgroup_dummy_top, ss));
+ BUG_ON(cgroup_css(cgrp, ss)->cgroup != cgrp);
if (ss->bind)
- ss->bind(cgroup_css(cgroup_dummy_top, i));
+ ss->bind(cgroup_css(cgroup_dummy_top, ss));
- cgroup_css(cgroup_dummy_top, i)->cgroup = cgroup_dummy_top;
+ cgroup_css(cgroup_dummy_top, ss)->cgroup = cgroup_dummy_top;
RCU_INIT_POINTER(cgrp->subsys[i], NULL);
cgroup_subsys[i]->root = &cgroup_dummy_root;
struct cgroup_subsys_state *cgroup_taskset_cur_css(struct cgroup_taskset *tset,
int subsys_id)
{
- return cgroup_css(tset->cur_cgrp, subsys_id);
+ return cgroup_css(tset->cur_cgrp, cgroup_subsys[subsys_id]);
}
EXPORT_SYMBOL_GPL(cgroup_taskset_cur_css);
* step 1: check that we can legitimately attach to the cgroup.
*/
for_each_root_subsys(root, ss) {
- struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id);
+ struct cgroup_subsys_state *css = cgroup_css(cgrp, ss);
if (ss->can_attach) {
retval = ss->can_attach(css, &tset);
* step 4: do subsystem attach callbacks.
*/
for_each_root_subsys(root, ss) {
- struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id);
+ struct cgroup_subsys_state *css = cgroup_css(cgrp, ss);
if (ss->attach)
ss->attach(css, &tset);
out_cancel_attach:
if (retval) {
for_each_root_subsys(root, ss) {
- struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id);
+ struct cgroup_subsys_state *css = cgroup_css(cgrp, ss);
if (ss == failed_ss)
break;
* @css stays alive for all file operations.
*/
rcu_read_lock();
- if (cft->ss) {
- css = cgroup_css(cgrp, cft->ss->subsys_id);
- if (!css_tryget(css))
- css = NULL;
- } else {
- css = &cgrp->dummy_css;
- }
+ css = cgroup_css(cgrp, cft->ss);
+ if (cft->ss && !css_tryget(css))
+ css = NULL;
rcu_read_unlock();
if (!css)
/* add/rm files for all cgroups created before */
rcu_read_lock();
- css_for_each_descendant_pre(css, cgroup_css(root, ss->subsys_id)) {
+ css_for_each_descendant_pre(css, cgroup_css(root, ss)) {
struct cgroup *cgrp = css->cgroup;
if (cgroup_is_dead(cgrp))
if (&next->sibling == &cgrp->children)
return NULL;
- if (parent_css->ss)
- return cgroup_css(next, parent_css->ss->subsys_id);
- else
- return &next->dummy_css;
+ return cgroup_css(next, parent_css->ss);
}
EXPORT_SYMBOL_GPL(css_next_child);
rcu_read_lock();
ret = -EINVAL;
- event->css = cgroup_css(cgrp, event->cft->ss->subsys_id);
+ event->css = cgroup_css(cgrp, event->cft->ss);
if (event->css)
ret = 0;
/* This cgroup is ready now */
for_each_root_subsys(cgrp->root, ss) {
- struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id);
+ struct cgroup_subsys_state *css = cgroup_css(cgrp, ss);
struct css_id *id = rcu_dereference_protected(css->id, true);
/*
css->id = NULL;
if (cgrp->parent)
- css->parent = cgroup_css(cgrp->parent, ss->subsys_id);
+ css->parent = cgroup_css(cgrp->parent, ss);
else
css->flags |= CSS_ROOT;
- BUG_ON(cgroup_css(cgrp, ss->subsys_id));
+ BUG_ON(cgroup_css(cgrp, ss));
}
/* invoke ->css_online() on a new CSS and mark it online if successful */
for_each_root_subsys(root, ss) {
struct cgroup_subsys_state *css;
- css = ss->css_alloc(cgroup_css(parent, ss->subsys_id));
+ css = ss->css_alloc(cgroup_css(parent, ss));
if (IS_ERR(css)) {
err = PTR_ERR(css);
goto err_free_all;
* percpu refs of all css's are confirmed to be killed.
*/
for_each_root_subsys(cgrp->root, ss)
- kill_css(cgroup_css(cgrp, ss->subsys_id));
+ kill_css(cgroup_css(cgrp, ss));
/*
* Mark @cgrp dead. This prevents further task migration and child
/* Create the top cgroup state for this subsystem */
list_add(&ss->sibling, &cgroup_dummy_root.subsys_list);
ss->root = &cgroup_dummy_root;
- css = ss->css_alloc(cgroup_css(cgroup_dummy_top, ss->subsys_id));
+ css = ss->css_alloc(cgroup_css(cgroup_dummy_top, ss));
/* We don't handle early failures gracefully */
BUG_ON(IS_ERR(css));
init_css(css, ss, cgroup_dummy_top);
* struct, so this can happen first (i.e. before the dummy root
* attachment).
*/
- css = ss->css_alloc(cgroup_css(cgroup_dummy_top, ss->subsys_id));
+ css = ss->css_alloc(cgroup_css(cgroup_dummy_top, ss));
if (IS_ERR(css)) {
/* failure case - need to deassign the cgroup_subsys[] slot. */
cgroup_subsys[ss->subsys_id] = NULL;
mutex_lock(&cgroup_mutex);
- offline_css(cgroup_css(cgroup_dummy_top, ss->subsys_id));
+ offline_css(cgroup_css(cgroup_dummy_top, ss));
if (ss->use_id)
idr_destroy(&ss->idr);
* the cgrp->subsys pointer to find their state. note that this
* also takes care of freeing the css_id.
*/
- ss->css_free(cgroup_css(cgroup_dummy_top, ss->subsys_id));
+ ss->css_free(cgroup_css(cgroup_dummy_top, ss));
RCU_INIT_POINTER(cgroup_dummy_top->subsys[ss->subsys_id], NULL);
mutex_unlock(&cgroup_mutex);
return ERR_PTR(-EBADF);
cgrp = __d_cgrp(dentry);
- return cgroup_css(cgrp, ss->subsys_id) ?: ERR_PTR(-ENOENT);
+ return cgroup_css(cgrp, ss) ?: ERR_PTR(-ENOENT);
}
/**