struct list_head node;
struct dentry *dentry;
struct cftype *type;
+ struct cgroup_subsys_state *css;
/* file xattrs */
struct simple_xattrs xattrs;
return 0;
}
-/* return the css for the given cgroup file */
-static struct cgroup_subsys_state *cgroup_file_css(struct cfent *cfe)
-{
- struct cftype *cft = cfe->type;
- struct cgroup *cgrp = __d_cgrp(cfe->dentry->d_parent);
-
- if (cft->ss)
- return cgroup_css(cgrp, cft->ss->subsys_id);
- return &cgrp->dummy_css;
-}
-
/* A buffer size big enough for numbers or short strings */
#define CGROUP_LOCAL_BUFFER_SIZE 64
{
struct cfent *cfe = __d_cfe(file->f_dentry);
struct cftype *cft = __d_cft(file->f_dentry);
- struct cgroup_subsys_state *css = cgroup_file_css(cfe);
+ struct cgroup_subsys_state *css = cfe->css;
if (cft->write)
return cft->write(css, cft, file, buf, nbytes, ppos);
{
struct cfent *cfe = __d_cfe(file->f_dentry);
struct cftype *cft = __d_cft(file->f_dentry);
- struct cgroup_subsys_state *css = cgroup_file_css(cfe);
+ struct cgroup_subsys_state *css = cfe->css;
if (cft->read)
return cft->read(css, cft, file, buf, nbytes, ppos);
{
struct cfent *cfe = m->private;
struct cftype *cft = cfe->type;
- struct cgroup_subsys_state *css = cgroup_file_css(cfe);
+ struct cgroup_subsys_state *css = cfe->css;
if (cft->read_map) {
struct cgroup_map_cb cb = {
{
struct cfent *cfe = __d_cfe(file->f_dentry);
struct cftype *cft = __d_cft(file->f_dentry);
- struct cgroup_subsys_state *css = cgroup_file_css(cfe);
+ struct cgroup *cgrp = __d_cgrp(cfe->dentry->d_parent);
+ struct cgroup_subsys_state *css;
int err;
err = generic_file_open(inode, file);
* unpinned either on open failure or release. This ensures that
* @css stays alive for all file operations.
*/
- if (css->ss && !css_tryget(css))
+ 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;
+ }
+ rcu_read_unlock();
+
+ /* css should match @cfe->css, see cgroup_add_file() for details */
+ if (!css || WARN_ON_ONCE(css != cfe->css))
return -ENODEV;
if (cft->read_map || cft->read_seq_string) {
{
struct cfent *cfe = __d_cfe(file->f_dentry);
struct cftype *cft = __d_cft(file->f_dentry);
- struct cgroup_subsys_state *css = cgroup_file_css(cfe);
+ struct cgroup_subsys_state *css = cfe->css;
int ret = 0;
if (cft->release)
dentry->d_fsdata = cfe;
simple_xattrs_init(&cfe->xattrs);
+ /*
+ * cfe->css is used by read/write/close to determine the associated
+ * css. file->private_data would be a better place but that's
+ * already used by seqfile. Note that open will use the usual
+ * cgroup_css() and css_tryget() to acquire the css and this
+ * caching doesn't affect css lifetime management.
+ */
+ if (cft->ss)
+ cfe->css = cgroup_css(cgrp, cft->ss->subsys_id);
+ else
+ cfe->css = &cgrp->dummy_css;
+
mode = cgroup_file_mode(cft);
error = cgroup_create_file(dentry, mode | S_IFREG, cgrp->root->sb);
if (!error) {