aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/cgroup.h
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2012-04-01 15:09:55 -0400
committerTejun Heo <tj@kernel.org>2012-04-01 15:09:55 -0400
commit8e3f6541d45e1a002801e56a19530a90f775deba (patch)
tree5342d7afce759252f5204c7e33283879cca0490d /include/linux/cgroup.h
parentb0ca5a84fc3ad8f75bb2b7ac3dc6a77151cd3906 (diff)
cgroup: implement cgroup_add_cftypes() and friends
Currently, cgroup directories are populated by subsys->populate() callback explicitly creating files on each cgroup creation. This level of flexibility isn't needed or desirable. It provides largely unused flexibility which call for abuses while severely limiting what the core layer can do through the lack of structure and conventions. Per each cgroup file type, the only distinction that cgroup users is making is whether a cgroup is root or not, which can easily be expressed with flags. This patch introduces cgroup_add_cftypes(). These deal with cftypes instead of individual files - controllers indicate that certain types of files exist for certain subsystem. Newly added CFTYPE_*_ON_ROOT flags indicate whether a cftype should be excluded or created only on the root cgroup. cgroup_add_cftypes() can be called any time whether the target subsystem is currently attached or not. cgroup core will create files on the existing cgroups as necessary. Also, cgroup_subsys->base_cftypes is added to ease registration of the base files for the subsystem. If non-NULL on subsys init, the cftypes pointed to by ->base_cftypes are automatically registered on subsys init / load. Further patches will convert the existing users and remove the file based interface. Note that this interface allows dynamic addition of files to an active controller. This will be used for sub-controller modularity and unified hierarchy in the longer term. This patch implements the new mechanism but doesn't apply it to any user. v2: replaced DECLARE_CGROUP_CFTYPES[_COND]() with cgroup_subsys->base_cftypes, which works better for cgroup_subsys which is loaded as module. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizf@cn.fujitsu.com>
Diffstat (limited to 'include/linux/cgroup.h')
-rw-r--r--include/linux/cgroup.h33
1 files changed, 31 insertions, 2 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index ad2a14680b7f..af6211c7a42b 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -192,6 +192,7 @@ struct cgroup {
192 struct list_head css_sets; 192 struct list_head css_sets;
193 193
194 struct list_head allcg_node; /* cgroupfs_root->allcg_list */ 194 struct list_head allcg_node; /* cgroupfs_root->allcg_list */
195 struct list_head cft_q_node; /* used during cftype add/rm */
195 196
196 /* 197 /*
197 * Linked list running through all cgroups that can 198 * Linked list running through all cgroups that can
@@ -277,11 +278,17 @@ struct cgroup_map_cb {
277 * - the 'cftype' of the file is file->f_dentry->d_fsdata 278 * - the 'cftype' of the file is file->f_dentry->d_fsdata
278 */ 279 */
279 280
280#define MAX_CFTYPE_NAME 64 281/* cftype->flags */
282#define CFTYPE_ONLY_ON_ROOT (1U << 0) /* only create on root cg */
283#define CFTYPE_NOT_ON_ROOT (1U << 1) /* don't create onp root cg */
284
285#define MAX_CFTYPE_NAME 64
286
281struct cftype { 287struct cftype {
282 /* 288 /*
283 * By convention, the name should begin with the name of the 289 * By convention, the name should begin with the name of the
284 * subsystem, followed by a period 290 * subsystem, followed by a period. Zero length string indicates
291 * end of cftype array.
285 */ 292 */
286 char name[MAX_CFTYPE_NAME]; 293 char name[MAX_CFTYPE_NAME];
287 int private; 294 int private;
@@ -297,6 +304,9 @@ struct cftype {
297 */ 304 */
298 size_t max_write_len; 305 size_t max_write_len;
299 306
307 /* CFTYPE_* flags */
308 unsigned int flags;
309
300 int (*open)(struct inode *inode, struct file *file); 310 int (*open)(struct inode *inode, struct file *file);
301 ssize_t (*read)(struct cgroup *cgrp, struct cftype *cft, 311 ssize_t (*read)(struct cgroup *cgrp, struct cftype *cft,
302 struct file *file, 312 struct file *file,
@@ -375,6 +385,16 @@ struct cftype {
375 struct eventfd_ctx *eventfd); 385 struct eventfd_ctx *eventfd);
376}; 386};
377 387
388/*
389 * cftype_sets describe cftypes belonging to a subsystem and are chained at
390 * cgroup_subsys->cftsets. Each cftset points to an array of cftypes
391 * terminated by zero length name.
392 */
393struct cftype_set {
394 struct list_head node; /* chained at subsys->cftsets */
395 const struct cftype *cfts;
396};
397
378struct cgroup_scanner { 398struct cgroup_scanner {
379 struct cgroup *cg; 399 struct cgroup *cg;
380 int (*test_task)(struct task_struct *p, struct cgroup_scanner *scan); 400 int (*test_task)(struct task_struct *p, struct cgroup_scanner *scan);
@@ -400,6 +420,8 @@ int cgroup_add_files(struct cgroup *cgrp,
400 const struct cftype cft[], 420 const struct cftype cft[],
401 int count); 421 int count);
402 422
423int cgroup_add_cftypes(struct cgroup_subsys *ss, const struct cftype *cfts);
424
403int cgroup_is_removed(const struct cgroup *cgrp); 425int cgroup_is_removed(const struct cgroup *cgrp);
404 426
405int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen); 427int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen);
@@ -502,6 +524,13 @@ struct cgroup_subsys {
502 struct idr idr; 524 struct idr idr;
503 spinlock_t id_lock; 525 spinlock_t id_lock;
504 526
527 /* list of cftype_sets */
528 struct list_head cftsets;
529
530 /* base cftypes, automatically [de]registered with subsys itself */
531 struct cftype *base_cftypes;
532 struct cftype_set base_cftset;
533
505 /* should be defined only by modular subsystems */ 534 /* should be defined only by modular subsystems */
506 struct module *module; 535 struct module *module;
507}; 536};