Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

Paste Description for bblum

cgroup modular test subsystem!

bblum
Sunday, October 11th, 2009 at 9:22:04pm UTC 

  1. #include <linux/module.h>
  2. #include <linux/cgroup.h>
  3. #include <linux/fs.h>
  4. #include <linux/slab.h>
  5.  
  6. MODULE_LICENSE("GPL");
  7. MODULE_AUTHOR("bblom");
  8.  
  9. u64 test1 = 0;
  10.  
  11. struct test1_cgroup {
  12.         struct cgroup_subsys_state css;
  13. };
  14.  
  15. static struct cgroup_subsys_state *test1_create(struct cgroup_subsys *ss,
  16.                                                 struct cgroup *cgroup)
  17. {
  18.         struct test1_cgroup *foo = kzalloc(sizeof(*foo), GFP_KERNEL);
  19.         if (!foo)
  20.                 return ERR_PTR(-ENOMEM);
  21.         return &foo->css;
  22. }
  23.  
  24. static int test1_can_attach(struct cgroup_subsys *ss, struct cgroup *new_cgroup,
  25.                             struct task_struct *task, bool threadgroup)
  26. {
  27.         if (test1 == 42)
  28.                 return 0;
  29.         return -EPERM;
  30. }
  31.  
  32. static int test1_write(struct cgroup *cgrp, struct cftype *cft, u64 val)
  33. {
  34.         test1 = val;
  35.         return 0;
  36. }
  37.  
  38. static u64 test1_read(struct cgroup *cgrp, struct cftype *cft)
  39. {
  40.         return test1;
  41. }
  42.  
  43. static struct cftype test1_file = {
  44.         .name = "hax",
  45.         .write_u64 = test1_write,
  46.         .read_u64 = test1_read,
  47. };
  48.  
  49. static int test1_populate(struct cgroup_subsys *ss, struct cgroup *cgroup)
  50. {
  51.         return cgroup_add_file(cgroup, ss, &test1_file);
  52. }
  53.  
  54. struct cgroup_subsys test1_subsys = {
  55.         .name = "test1",
  56.         .can_attach = test1_can_attach,
  57.         .create = test1_create,
  58.         .populate = test1_populate,
  59.         .module = THIS_MODULE,
  60. };
  61.  
  62. static int test1_load(void)
  63. {
  64.         return cgroup_load_subsys(&test1_subsys);
  65. }
  66. module_init(test1_load);

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right