Lines Matching refs:css

110  * against file removal/re-creation across css hiding.
249 static void kill_css(struct cgroup_subsys_state *css);
250 static int cgroup_addrm_files(struct cgroup_subsys_state *css,
477 * cgroup_css - obtain a cgroup's css for the specified subsystem
481 * Return @cgrp's css (cgroup_subsys_state) associated with @ss. This
483 * the caller is responsible for pinning the returned css if it wants to
498 * cgroup_e_css_by_mask - obtain a cgroup's effective css for the specified ss
502 * Similar to cgroup_css() but returns the effective css, which is defined
503 * as the matching css of the nearest ancestor including self which has @ss
505 * function is guaranteed to return non-NULL css.
516 * This function is used while updating css associations and thus
529 * cgroup_e_css - obtain a cgroup's effective css for the specified subsystem
533 * Find and get the effective css of @cgrp for @ss. The effective css is
534 * defined as the matching css of the nearest ancestor including self which
536 * the root css is returned, so this function always returns a valid css.
538 * The returned css is not guaranteed to be online, and therefore it is the
544 struct cgroup_subsys_state *css;
550 css = cgroup_css(cgrp, ss);
552 if (css)
553 return css;
561 * cgroup_get_e_css - get a cgroup's effective css for the specified subsystem
565 * Find and get the effective css of @cgrp for @ss. The effective css is
566 * defined as the matching css of the nearest ancestor including self which
568 * the root css is returned, so this function always returns a valid css.
569 * The returned css must be put using css_put().
574 struct cgroup_subsys_state *css;
582 css = cgroup_css(cgrp, ss);
584 if (css && css_tryget_online(css))
589 css = init_css_set.subsys[ss->id];
590 css_get(css);
593 return css;
645 * files are drained before a css is disassociated with a cgroup,
646 * the matching css from the cgroup's subsys table is guaranteed to
657 * for_each_css - iterate all css's of a cgroup
658 * @css: the iteration cursor
660 * @cgrp: the target cgroup to iterate css's of
664 #define for_each_css(css, ssid, cgrp) \
666 if (!((css) = rcu_dereference_check( \
912 static unsigned long css_set_hash(struct cgroup_subsys_state **css)
919 key += (unsigned long)css[i];
938 /* This css_set is dead. Unlink it and release cgroup and css refs */
967 * @template: desired set of css pointers in css_set (pre-calculated)
1001 * share the same effective css, this comparison is always
1046 * find_existing_css_set - init css array and find the matching css_set
1070 * effective css from @cgrp.
1076 * to change the css.
1240 struct cgroup_subsys_state *css = cset->subsys[ssid];
1243 &css->cgroup->e_csets[ssid]);
1244 css_get(css);
1678 struct cgroup_subsys_state *css = cgroup_css(cgrp, cft->ss);
1679 struct cgroup_file *cfile = (void *)css + cft->file_offset;
1693 * @css: target css
1695 static void css_clear_dir(struct cgroup_subsys_state *css)
1697 struct cgroup *cgrp = css->cgroup;
1700 if (!(css->flags & CSS_VISIBLE))
1703 css->flags &= ~CSS_VISIBLE;
1705 if (!css->ss) {
1707 cgroup_addrm_files(css, cgrp,
1710 cgroup_addrm_files(css, cgrp,
1713 cgroup_addrm_files(css, cgrp,
1717 list_for_each_entry(cfts, &css->ss->cfts, node)
1718 cgroup_addrm_files(css, cgrp, cfts, false);
1724 * @css: target css
1728 static int css_populate_dir(struct cgroup_subsys_state *css)
1730 struct cgroup *cgrp = css->cgroup;
1734 if (css->flags & CSS_VISIBLE)
1737 if (!css->ss) {
1739 ret = cgroup_addrm_files(css, cgrp,
1745 ret = cgroup_addrm_files(css, cgrp,
1751 ret = cgroup_addrm_files(css, cgrp,
1757 list_for_each_entry(cfts, &css->ss->cfts, node) {
1758 ret = cgroup_addrm_files(css, cgrp, cfts, true);
1766 css->flags |= CSS_VISIBLE;
1770 list_for_each_entry(cfts, &css->ss->cfts, node) {
1773 cgroup_addrm_files(css, cgrp, cfts, false);
1825 struct cgroup_subsys_state *css = cgroup_css(scgrp, ss);
1829 WARN_ON(!css || cgroup_css(dcgrp, ss));
1840 rcu_assign_pointer(dcgrp->subsys[ssid], css);
1842 css->cgroup = dcgrp;
1864 list_del_rcu(&css->rstat_css_node);
1866 list_add_rcu(&css->rstat_css_node,
1885 ss->bind(css);
2471 * @dst_cssp: output variable for the destination css
2487 * @dst_cssp: output variable for the destination css
3005 * cgroup_update_dfl_csses - update css assoc of a subtree in default hierarchy
3008 * @cgrp's control masks have changed and its subtree's css associations
3079 * Because css offlining is asynchronous, userland may try to re-enable a
3080 * controller while the previous css is still around. This function grabs
3081 * cgroup_mutex and drains the previous css instances of @cgrp's subtree.
3096 struct cgroup_subsys_state *css = cgroup_css(dsct, ss);
3099 if (!css || !percpu_ref_is_dying(&css->refcnt))
3177 static bool css_visible(struct cgroup_subsys_state *css)
3179 struct cgroup_subsys *ss = css->ss;
3180 struct cgroup *cgrp = css->cgroup;
3194 * visible. A css is created invisible if it's being implicitly enabled
3195 * through dependency. An invisible css is made visible when the userland
3211 struct cgroup_subsys_state *css = cgroup_css(dsct, ss);
3216 if (!css) {
3217 css = css_create(dsct, ss);
3218 if (IS_ERR(css))
3219 return PTR_ERR(css);
3222 WARN_ON_ONCE(percpu_ref_is_dying(&css->refcnt));
3224 if (css_visible(css)) {
3225 ret = css_populate_dir(css);
3242 * A css is hidden when the userland requests it to be disabled while other
3243 * subsystems are still depending on it. The css must not actively control
3257 struct cgroup_subsys_state *css = cgroup_css(dsct, ss);
3259 if (!css)
3262 WARN_ON_ONCE(percpu_ref_is_dying(&css->refcnt));
3264 if (css->parent &&
3266 kill_css(css);
3267 } else if (!css_visible(css)) {
3268 css_clear_dir(css);
3270 ss->css_reset(css);
3306 * css associations of all tasks in the subtree.
3668 * cgroup_tryget_css - try to get a cgroup's css for the specified subsystem
3672 * Find and get @cgrp's css associated with @ss. If the css doesn't exist
3678 struct cgroup_subsys_state *css;
3681 css = cgroup_css(cgrp, ss);
3682 if (css && !css_tryget_online(css))
3683 css = NULL;
3686 return css;
3693 struct cgroup_subsys_state *css;
3699 css = cgroup_tryget_css(cgrp, ss);
3700 if (!css)
3703 ret = ss->css_extra_stat_show(seq, css);
3704 css_put(css);
3712 struct cgroup_subsys_state *css;
3718 css = cgroup_tryget_css(cgrp, ss);
3719 if (!css)
3722 ret = ss->css_local_stat_show(seq, css);
3723 css_put(css);
3990 struct cgroup_subsys_state *css;
3995 cgroup_for_each_live_descendant_pre(dsct, css, cgrp)
4074 struct cgroup_subsys_state *css;
4096 * flight, which means that the matching css is and stays alive and
4101 css = cgroup_css(cgrp, cft->ss);
4108 ret = cft->write_u64(css, cft, v);
4113 ret = cft->write_s64(css, cft, v);
4150 struct cgroup_subsys_state *css = seq_css(m);
4156 seq_printf(m, "%llu\n", cft->read_u64(css, cft));
4158 seq_printf(m, "%lld\n", cft->read_s64(css, cft));
4191 static int cgroup_add_file(struct cgroup_subsys_state *css, struct cgroup *cgrp,
4210 struct cgroup_file *cfile = (void *)css + cft->file_offset;
4224 * @css: the target css
4225 * @cgrp: the target cgroup (usually css->cgroup)
4232 static int cgroup_addrm_files(struct cgroup_subsys_state *css,
4255 ret = cgroup_add_file(css, cgrp, cft);
4274 struct cgroup_subsys_state *css;
4280 css_for_each_descendant_pre(css, cgroup_css(root, ss)) {
4281 struct cgroup *cgrp = css->cgroup;
4283 if (!(css->flags & CSS_VISIBLE))
4286 ret = cgroup_addrm_files(css, cgrp, cfts, is_add);
4509 * css_next_child - find the next child of a given css
4511 * @parent: css whose children to walk
4519 * css which finished ->css_online() is guaranteed to be visible in the
4521 * A css which hasn't finished ->css_online() or already finished
4545 * dereferenced; however, as each css is given a monotonically
4548 * children until the first css with higher serial number than
4575 * @root: css whose descendants to walk
4587 * css which finished ->css_online() is guaranteed to be visible in the
4589 * A css which hasn't finished ->css_online() or already finished
4623 * css_rightmost_descendant - return the rightmost descendant of a css
4624 * @pos: css of interest
4669 * @root: css whose descendants to walk
4682 * css which finished ->css_online() is guaranteed to be visible in the
4684 * A css which hasn't finished ->css_online() or already finished
4714 * css_has_online_children - does a css have online children
4715 * @css: the target css
4717 * Returns %true if @css has any online children; otherwise, %false. This
4721 bool css_has_online_children(struct cgroup_subsys_state *css)
4727 css_for_each_child(child, css) {
4910 * @css: the css to walk tasks of
4914 * Initiate iteration through the tasks of @css. The caller can call
4919 void css_task_iter_start(struct cgroup_subsys_state *css, unsigned int flags,
4928 it->ss = css->ss;
4932 it->cset_pos = &css->cgroup->e_csets[css->ss->id];
4934 it->cset_pos = &css->cgroup->cset_links;
5327 * css destruction is four-stage process.
5333 * and thus css_tryget_online() is guaranteed to fail, the css can be
5341 * 4. After the grace period, the css can be freed. Implemented in
5345 * and thus involve punting to css->destroy_work adding two additional
5350 struct cgroup_subsys_state *css = container_of(to_rcu_work(work),
5352 struct cgroup_subsys *ss = css->ss;
5353 struct cgroup *cgrp = css->cgroup;
5355 percpu_ref_exit(&css->refcnt);
5358 /* css free path */
5359 struct cgroup_subsys_state *parent = css->parent;
5360 int id = css->id;
5362 ss->css_free(css);
5400 struct cgroup_subsys_state *css =
5402 struct cgroup_subsys *ss = css->ss;
5403 struct cgroup *cgrp = css->cgroup;
5407 css->flags |= CSS_RELEASED;
5408 list_del_rcu(&css->sibling);
5411 /* css release path */
5412 if (!list_empty(&css->rstat_css_node)) {
5414 list_del_rcu(&css->rstat_css_node);
5417 cgroup_idr_replace(&ss->css_idr, NULL, css->id);
5419 ss->css_released(css);
5448 INIT_RCU_WORK(&css->destroy_rwork, css_free_rwork_fn);
5449 queue_rcu_work(cgroup_destroy_wq, &css->destroy_rwork);
5454 struct cgroup_subsys_state *css =
5457 INIT_WORK(&css->destroy_work, css_release_work_fn);
5458 queue_work(cgroup_destroy_wq, &css->destroy_work);
5461 static void init_and_link_css(struct cgroup_subsys_state *css,
5468 memset(css, 0, sizeof(*css));
5469 css->cgroup = cgrp;
5470 css->ss = ss;
5471 css->id = -1;
5472 INIT_LIST_HEAD(&css->sibling);
5473 INIT_LIST_HEAD(&css->children);
5474 INIT_LIST_HEAD(&css->rstat_css_node);
5475 css->serial_nr = css_serial_nr_next++;
5476 atomic_set(&css->online_cnt, 0);
5479 css->parent = cgroup_css(cgroup_parent(cgrp), ss);
5480 css_get(css->parent);
5484 list_add_rcu(&css->rstat_css_node, &cgrp->rstat_css_list);
5490 static int online_css(struct cgroup_subsys_state *css)
5492 struct cgroup_subsys *ss = css->ss;
5498 ret = ss->css_online(css);
5500 css->flags |= CSS_ONLINE;
5501 rcu_assign_pointer(css->cgroup->subsys[ss->id], css);
5503 atomic_inc(&css->online_cnt);
5504 if (css->parent)
5505 atomic_inc(&css->parent->online_cnt);
5511 static void offline_css(struct cgroup_subsys_state *css)
5513 struct cgroup_subsys *ss = css->ss;
5517 if (!(css->flags & CSS_ONLINE))
5521 ss->css_offline(css);
5523 css->flags &= ~CSS_ONLINE;
5524 RCU_INIT_POINTER(css->cgroup->subsys[ss->id], NULL);
5526 wake_up_all(&css->cgroup->offline_waitq);
5531 * @cgrp: the cgroup new css will be associated with
5532 * @ss: the subsys of new css
5534 * Create a new css associated with @cgrp - @ss pair. On success, the new
5535 * css is online and installed in @cgrp. This function doesn't create the
5543 struct cgroup_subsys_state *css;
5548 css = ss->css_alloc(parent_css);
5549 if (!css)
5550 css = ERR_PTR(-ENOMEM);
5551 if (IS_ERR(css))
5552 return css;
5554 init_and_link_css(css, ss, cgrp);
5556 err = percpu_ref_init(&css->refcnt, css_release, 0, GFP_KERNEL);
5563 css->id = err;
5565 /* @css is ready to be brought online now, make it visible */
5566 list_add_tail_rcu(&css->sibling, &parent_css->children);
5567 cgroup_idr_replace(&ss->css_idr, css, css->id);
5569 err = online_css(css);
5573 return css;
5576 list_del_rcu(&css->sibling);
5578 list_del_rcu(&css->rstat_css_node);
5579 INIT_RCU_WORK(&css->destroy_rwork, css_free_rwork_fn);
5580 queue_rcu_work(cgroup_destroy_wq, &css->destroy_rwork);
5768 /* let's create and online css's */
5782 * This is called when the refcnt of a css is confirmed to be killed.
5784 * initiate destruction and put the css ref from kill_css().
5788 struct cgroup_subsys_state *css =
5794 offline_css(css);
5795 css_put(css);
5796 /* @css can't go away while we're holding cgroup_mutex */
5797 css = css->parent;
5798 } while (css && atomic_dec_and_test(&css->online_cnt));
5803 /* css kill confirmation processing requires process context, bounce */
5806 struct cgroup_subsys_state *css =
5809 if (atomic_dec_and_test(&css->online_cnt)) {
5810 INIT_WORK(&css->destroy_work, css_killed_work_fn);
5811 queue_work(cgroup_destroy_wq, &css->destroy_work);
5816 * kill_css - destroy a css
5817 * @css: css to destroy
5819 * This function initiates destruction of @css by removing cgroup interface
5822 * the reference count reaches zero, @css will be released.
5824 static void kill_css(struct cgroup_subsys_state *css)
5828 if (css->flags & CSS_DYING)
5831 css->flags |= CSS_DYING;
5834 * This must happen before css is disassociated with its cgroup.
5837 css_clear_dir(css);
5843 css_get(css);
5847 * invoked, no new css reference will be given out via
5849 * proceed to offlining css's because percpu_ref_kill() doesn't
5853 * css is confirmed to be seen as killed on all CPUs.
5855 percpu_ref_kill_and_confirm(&css->refcnt, css_killed_ref_fn);
5862 * css's make use of percpu refcnts whose killing latency shouldn't be
5870 * css's. Set up so that the next stage will be kicked off once all
5886 struct cgroup_subsys_state *css;
5920 /* initiate massacre of all css's */
5921 for_each_css(css, ssid, cgrp)
5922 kill_css(css);
5980 struct cgroup_subsys_state *css;
5991 css = ss->css_alloc(NULL);
5993 BUG_ON(IS_ERR(css));
5994 init_and_link_css(css, ss, &cgrp_dfl_root.cgrp);
6000 css->flags |= CSS_NO_REF;
6004 css->id = 1;
6006 css->id = cgroup_idr_alloc(&ss->css_idr, css, 1, 2, GFP_KERNEL);
6007 BUG_ON(css->id < 0);
6014 init_css_set.subsys[ss->id] = css;
6026 BUG_ON(online_css(css));
6103 struct cgroup_subsys_state *css =
6106 css->id = cgroup_idr_alloc(&ss->css_idr, css, 1, 2,
6108 BUG_ON(css->id < 0);
6344 struct cgroup_subsys_state *css;
6346 css = css_tryget_online_from_dir(f->f_path.dentry, NULL);
6347 if (IS_ERR(css))
6348 return ERR_CAST(css);
6350 return css->cgroup;
6778 * css_tryget_online_from_dir - get corresponding css from a cgroup dentry
6783 * to get the corresponding css and return it. If such css doesn't exist
6791 struct cgroup_subsys_state *css = NULL;
6808 css = cgroup_css(cgrp, ss);
6810 if (!css || !css_tryget_online(css))
6811 css = ERR_PTR(-ENOENT);
6814 return css;
6818 * css_from_id - lookup css by id
6822 * Returns the css if there's valid one with @id, otherwise returns NULL.