aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorLi Zefan <lizf@cn.fujitsu.com>2009-01-07 21:07:42 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-08 11:31:03 -0500
commitc12f65d4396e05c51ce3af7f159ead98574a587c (patch)
tree95e4f2e4878101ca2b9e3efc0a9cc5f25ce678d7 /kernel
parent33a68ac1c1b695216e873ee12e819adbe73e4d9f (diff)
cgroups: introduce link_css_set() to remove duplicate code
Add a common function link_css_set() to link a css_set to a cgroup. Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Cc: Paul Menage <menage@google.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Balbir Singh <balbir@in.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/cgroup.c68
1 files changed, 30 insertions, 38 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index abf7248f501a..4c475ce4e222 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -384,6 +384,25 @@ static int allocate_cg_links(int count, struct list_head *tmp)
384 return 0; 384 return 0;
385} 385}
386 386
387/**
388 * link_css_set - a helper function to link a css_set to a cgroup
389 * @tmp_cg_links: cg_cgroup_link objects allocated by allocate_cg_links()
390 * @cg: the css_set to be linked
391 * @cgrp: the destination cgroup
392 */
393static void link_css_set(struct list_head *tmp_cg_links,
394 struct css_set *cg, struct cgroup *cgrp)
395{
396 struct cg_cgroup_link *link;
397
398 BUG_ON(list_empty(tmp_cg_links));
399 link = list_first_entry(tmp_cg_links, struct cg_cgroup_link,
400 cgrp_link_list);
401 link->cg = cg;
402 list_move(&link->cgrp_link_list, &cgrp->css_sets);
403 list_add(&link->cg_link_list, &cg->cg_links);
404}
405
387/* 406/*
388 * find_css_set() takes an existing cgroup group and a 407 * find_css_set() takes an existing cgroup group and a
389 * cgroup object, and returns a css_set object that's 408 * cgroup object, and returns a css_set object that's
@@ -399,7 +418,6 @@ static struct css_set *find_css_set(
399 int i; 418 int i;
400 419
401 struct list_head tmp_cg_links; 420 struct list_head tmp_cg_links;
402 struct cg_cgroup_link *link;
403 421
404 struct hlist_head *hhead; 422 struct hlist_head *hhead;
405 423
@@ -444,26 +462,11 @@ static struct css_set *find_css_set(
444 * only do it for the first subsystem in each 462 * only do it for the first subsystem in each
445 * hierarchy 463 * hierarchy
446 */ 464 */
447 if (ss->root->subsys_list.next == &ss->sibling) { 465 if (ss->root->subsys_list.next == &ss->sibling)
448 BUG_ON(list_empty(&tmp_cg_links)); 466 link_css_set(&tmp_cg_links, res, cgrp);
449 link = list_entry(tmp_cg_links.next,
450 struct cg_cgroup_link,
451 cgrp_link_list);
452 list_del(&link->cgrp_link_list);
453 list_add(&link->cgrp_link_list, &cgrp->css_sets);
454 link->cg = res;
455 list_add(&link->cg_link_list, &res->cg_links);
456 }
457 }
458 if (list_empty(&rootnode.subsys_list)) {
459 link = list_entry(tmp_cg_links.next,
460 struct cg_cgroup_link,
461 cgrp_link_list);
462 list_del(&link->cgrp_link_list);
463 list_add(&link->cgrp_link_list, &dummytop->css_sets);
464 link->cg = res;
465 list_add(&link->cg_link_list, &res->cg_links);
466 } 467 }
468 if (list_empty(&rootnode.subsys_list))
469 link_css_set(&tmp_cg_links, res, dummytop);
467 470
468 BUG_ON(!list_empty(&tmp_cg_links)); 471 BUG_ON(!list_empty(&tmp_cg_links));
469 472
@@ -988,7 +991,7 @@ static int cgroup_get_sb(struct file_system_type *fs_type,
988 root = NULL; 991 root = NULL;
989 } else { 992 } else {
990 /* New superblock */ 993 /* New superblock */
991 struct cgroup *cgrp = &root->top_cgroup; 994 struct cgroup *root_cgrp = &root->top_cgroup;
992 struct inode *inode; 995 struct inode *inode;
993 int i; 996 int i;
994 997
@@ -1029,7 +1032,7 @@ static int cgroup_get_sb(struct file_system_type *fs_type,
1029 list_add(&root->root_list, &roots); 1032 list_add(&root->root_list, &roots);
1030 root_count++; 1033 root_count++;
1031 1034
1032 sb->s_root->d_fsdata = &root->top_cgroup; 1035 sb->s_root->d_fsdata = root_cgrp;
1033 root->top_cgroup.dentry = sb->s_root; 1036 root->top_cgroup.dentry = sb->s_root;
1034 1037
1035 /* Link the top cgroup in this hierarchy into all 1038 /* Link the top cgroup in this hierarchy into all
@@ -1040,29 +1043,18 @@ static int cgroup_get_sb(struct file_system_type *fs_type,
1040 struct hlist_node *node; 1043 struct hlist_node *node;
1041 struct css_set *cg; 1044 struct css_set *cg;
1042 1045
1043 hlist_for_each_entry(cg, node, hhead, hlist) { 1046 hlist_for_each_entry(cg, node, hhead, hlist)
1044 struct cg_cgroup_link *link; 1047 link_css_set(&tmp_cg_links, cg, root_cgrp);
1045
1046 BUG_ON(list_empty(&tmp_cg_links));
1047 link = list_entry(tmp_cg_links.next,
1048 struct cg_cgroup_link,
1049 cgrp_link_list);
1050 list_del(&link->cgrp_link_list);
1051 link->cg = cg;
1052 list_add(&link->cgrp_link_list,
1053 &root->top_cgroup.css_sets);
1054 list_add(&link->cg_link_list, &cg->cg_links);
1055 }
1056 } 1048 }
1057 write_unlock(&css_set_lock); 1049 write_unlock(&css_set_lock);
1058 1050
1059 free_cg_links(&tmp_cg_links); 1051 free_cg_links(&tmp_cg_links);
1060 1052
1061 BUG_ON(!list_empty(&cgrp->sibling)); 1053 BUG_ON(!list_empty(&root_cgrp->sibling));
1062 BUG_ON(!list_empty(&cgrp->children)); 1054 BUG_ON(!list_empty(&root_cgrp->children));
1063 BUG_ON(root->number_of_cgroups != 1); 1055 BUG_ON(root->number_of_cgroups != 1);
1064 1056
1065 cgroup_populate_dir(cgrp); 1057 cgroup_populate_dir(root_cgrp);
1066 mutex_unlock(&inode->i_mutex); 1058 mutex_unlock(&inode->i_mutex);
1067 mutex_unlock(&cgroup_mutex); 1059 mutex_unlock(&cgroup_mutex);
1068 } 1060 }