diff options
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r-- | kernel/cgroup.c | 76 |
1 files changed, 12 insertions, 64 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 2097684cf194..79818507e444 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -822,7 +822,7 @@ EXPORT_SYMBOL_GPL(cgroup_unlock); | |||
822 | */ | 822 | */ |
823 | 823 | ||
824 | static int cgroup_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode); | 824 | static int cgroup_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode); |
825 | static struct dentry *cgroup_lookup(struct inode *, struct dentry *, struct nameidata *); | 825 | static struct dentry *cgroup_lookup(struct inode *, struct dentry *, unsigned int); |
826 | static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry); | 826 | static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry); |
827 | static int cgroup_populate_dir(struct cgroup *cgrp); | 827 | static int cgroup_populate_dir(struct cgroup *cgrp); |
828 | static const struct inode_operations cgroup_dir_inode_operations; | 828 | static const struct inode_operations cgroup_dir_inode_operations; |
@@ -901,13 +901,10 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode) | |||
901 | mutex_unlock(&cgroup_mutex); | 901 | mutex_unlock(&cgroup_mutex); |
902 | 902 | ||
903 | /* | 903 | /* |
904 | * We want to drop the active superblock reference from the | 904 | * Drop the active superblock reference that we took when we |
905 | * cgroup creation after all the dentry refs are gone - | 905 | * created the cgroup |
906 | * kill_sb gets mighty unhappy otherwise. Mark | ||
907 | * dentry->d_fsdata with cgroup_diput() to tell | ||
908 | * cgroup_d_release() to call deactivate_super(). | ||
909 | */ | 906 | */ |
910 | dentry->d_fsdata = cgroup_diput; | 907 | deactivate_super(cgrp->root->sb); |
911 | 908 | ||
912 | /* | 909 | /* |
913 | * if we're getting rid of the cgroup, refcount should ensure | 910 | * if we're getting rid of the cgroup, refcount should ensure |
@@ -933,13 +930,6 @@ static int cgroup_delete(const struct dentry *d) | |||
933 | return 1; | 930 | return 1; |
934 | } | 931 | } |
935 | 932 | ||
936 | static void cgroup_d_release(struct dentry *dentry) | ||
937 | { | ||
938 | /* did cgroup_diput() tell me to deactivate super? */ | ||
939 | if (dentry->d_fsdata == cgroup_diput) | ||
940 | deactivate_super(dentry->d_sb); | ||
941 | } | ||
942 | |||
943 | static void remove_dir(struct dentry *d) | 933 | static void remove_dir(struct dentry *d) |
944 | { | 934 | { |
945 | struct dentry *parent = dget(d->d_parent); | 935 | struct dentry *parent = dget(d->d_parent); |
@@ -964,7 +954,7 @@ static int cgroup_rm_file(struct cgroup *cgrp, const struct cftype *cft) | |||
964 | 954 | ||
965 | dget(d); | 955 | dget(d); |
966 | d_delete(d); | 956 | d_delete(d); |
967 | simple_unlink(d->d_inode, d); | 957 | simple_unlink(cgrp->dentry->d_inode, d); |
968 | list_del_init(&cfe->node); | 958 | list_del_init(&cfe->node); |
969 | dput(d); | 959 | dput(d); |
970 | 960 | ||
@@ -1078,28 +1068,24 @@ static int rebind_subsystems(struct cgroupfs_root *root, | |||
1078 | BUG_ON(cgrp->subsys[i]); | 1068 | BUG_ON(cgrp->subsys[i]); |
1079 | BUG_ON(!dummytop->subsys[i]); | 1069 | BUG_ON(!dummytop->subsys[i]); |
1080 | BUG_ON(dummytop->subsys[i]->cgroup != dummytop); | 1070 | BUG_ON(dummytop->subsys[i]->cgroup != dummytop); |
1081 | mutex_lock(&ss->hierarchy_mutex); | ||
1082 | cgrp->subsys[i] = dummytop->subsys[i]; | 1071 | cgrp->subsys[i] = dummytop->subsys[i]; |
1083 | cgrp->subsys[i]->cgroup = cgrp; | 1072 | cgrp->subsys[i]->cgroup = cgrp; |
1084 | list_move(&ss->sibling, &root->subsys_list); | 1073 | list_move(&ss->sibling, &root->subsys_list); |
1085 | ss->root = root; | 1074 | ss->root = root; |
1086 | if (ss->bind) | 1075 | if (ss->bind) |
1087 | ss->bind(cgrp); | 1076 | ss->bind(cgrp); |
1088 | mutex_unlock(&ss->hierarchy_mutex); | ||
1089 | /* refcount was already taken, and we're keeping it */ | 1077 | /* refcount was already taken, and we're keeping it */ |
1090 | } else if (bit & removed_bits) { | 1078 | } else if (bit & removed_bits) { |
1091 | /* We're removing this subsystem */ | 1079 | /* We're removing this subsystem */ |
1092 | BUG_ON(ss == NULL); | 1080 | BUG_ON(ss == NULL); |
1093 | BUG_ON(cgrp->subsys[i] != dummytop->subsys[i]); | 1081 | BUG_ON(cgrp->subsys[i] != dummytop->subsys[i]); |
1094 | BUG_ON(cgrp->subsys[i]->cgroup != cgrp); | 1082 | BUG_ON(cgrp->subsys[i]->cgroup != cgrp); |
1095 | mutex_lock(&ss->hierarchy_mutex); | ||
1096 | if (ss->bind) | 1083 | if (ss->bind) |
1097 | ss->bind(dummytop); | 1084 | ss->bind(dummytop); |
1098 | dummytop->subsys[i]->cgroup = dummytop; | 1085 | dummytop->subsys[i]->cgroup = dummytop; |
1099 | cgrp->subsys[i] = NULL; | 1086 | cgrp->subsys[i] = NULL; |
1100 | subsys[i]->root = &rootnode; | 1087 | subsys[i]->root = &rootnode; |
1101 | list_move(&ss->sibling, &rootnode.subsys_list); | 1088 | list_move(&ss->sibling, &rootnode.subsys_list); |
1102 | mutex_unlock(&ss->hierarchy_mutex); | ||
1103 | /* subsystem is now free - drop reference on module */ | 1089 | /* subsystem is now free - drop reference on module */ |
1104 | module_put(ss->module); | 1090 | module_put(ss->module); |
1105 | } else if (bit & final_bits) { | 1091 | } else if (bit & final_bits) { |
@@ -1547,7 +1533,6 @@ static int cgroup_get_rootdir(struct super_block *sb) | |||
1547 | static const struct dentry_operations cgroup_dops = { | 1533 | static const struct dentry_operations cgroup_dops = { |
1548 | .d_iput = cgroup_diput, | 1534 | .d_iput = cgroup_diput, |
1549 | .d_delete = cgroup_delete, | 1535 | .d_delete = cgroup_delete, |
1550 | .d_release = cgroup_d_release, | ||
1551 | }; | 1536 | }; |
1552 | 1537 | ||
1553 | struct inode *inode = | 1538 | struct inode *inode = |
@@ -1598,7 +1583,7 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type, | |||
1598 | opts.new_root = new_root; | 1583 | opts.new_root = new_root; |
1599 | 1584 | ||
1600 | /* Locate an existing or new sb for this hierarchy */ | 1585 | /* Locate an existing or new sb for this hierarchy */ |
1601 | sb = sget(fs_type, cgroup_test_super, cgroup_set_super, &opts); | 1586 | sb = sget(fs_type, cgroup_test_super, cgroup_set_super, 0, &opts); |
1602 | if (IS_ERR(sb)) { | 1587 | if (IS_ERR(sb)) { |
1603 | ret = PTR_ERR(sb); | 1588 | ret = PTR_ERR(sb); |
1604 | cgroup_drop_root(opts.new_root); | 1589 | cgroup_drop_root(opts.new_root); |
@@ -2581,7 +2566,7 @@ static const struct inode_operations cgroup_dir_inode_operations = { | |||
2581 | .rename = cgroup_rename, | 2566 | .rename = cgroup_rename, |
2582 | }; | 2567 | }; |
2583 | 2568 | ||
2584 | static struct dentry *cgroup_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) | 2569 | static struct dentry *cgroup_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) |
2585 | { | 2570 | { |
2586 | if (dentry->d_name.len > NAME_MAX) | 2571 | if (dentry->d_name.len > NAME_MAX) |
2587 | return ERR_PTR(-ENAMETOOLONG); | 2572 | return ERR_PTR(-ENAMETOOLONG); |
@@ -3894,8 +3879,12 @@ static void css_dput_fn(struct work_struct *work) | |||
3894 | { | 3879 | { |
3895 | struct cgroup_subsys_state *css = | 3880 | struct cgroup_subsys_state *css = |
3896 | container_of(work, struct cgroup_subsys_state, dput_work); | 3881 | container_of(work, struct cgroup_subsys_state, dput_work); |
3882 | struct dentry *dentry = css->cgroup->dentry; | ||
3883 | struct super_block *sb = dentry->d_sb; | ||
3897 | 3884 | ||
3898 | dput(css->cgroup->dentry); | 3885 | atomic_inc(&sb->s_active); |
3886 | dput(dentry); | ||
3887 | deactivate_super(sb); | ||
3899 | } | 3888 | } |
3900 | 3889 | ||
3901 | static void init_cgroup_css(struct cgroup_subsys_state *css, | 3890 | static void init_cgroup_css(struct cgroup_subsys_state *css, |
@@ -3922,37 +3911,6 @@ static void init_cgroup_css(struct cgroup_subsys_state *css, | |||
3922 | set_bit(CSS_CLEAR_CSS_REFS, &css->flags); | 3911 | set_bit(CSS_CLEAR_CSS_REFS, &css->flags); |
3923 | } | 3912 | } |
3924 | 3913 | ||
3925 | static void cgroup_lock_hierarchy(struct cgroupfs_root *root) | ||
3926 | { | ||
3927 | /* We need to take each hierarchy_mutex in a consistent order */ | ||
3928 | int i; | ||
3929 | |||
3930 | /* | ||
3931 | * No worry about a race with rebind_subsystems that might mess up the | ||
3932 | * locking order, since both parties are under cgroup_mutex. | ||
3933 | */ | ||
3934 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | ||
3935 | struct cgroup_subsys *ss = subsys[i]; | ||
3936 | if (ss == NULL) | ||
3937 | continue; | ||
3938 | if (ss->root == root) | ||
3939 | mutex_lock(&ss->hierarchy_mutex); | ||
3940 | } | ||
3941 | } | ||
3942 | |||
3943 | static void cgroup_unlock_hierarchy(struct cgroupfs_root *root) | ||
3944 | { | ||
3945 | int i; | ||
3946 | |||
3947 | for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) { | ||
3948 | struct cgroup_subsys *ss = subsys[i]; | ||
3949 | if (ss == NULL) | ||
3950 | continue; | ||
3951 | if (ss->root == root) | ||
3952 | mutex_unlock(&ss->hierarchy_mutex); | ||
3953 | } | ||
3954 | } | ||
3955 | |||
3956 | /* | 3914 | /* |
3957 | * cgroup_create - create a cgroup | 3915 | * cgroup_create - create a cgroup |
3958 | * @parent: cgroup that will be parent of the new cgroup | 3916 | * @parent: cgroup that will be parent of the new cgroup |
@@ -4013,9 +3971,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
4013 | ss->post_clone(cgrp); | 3971 | ss->post_clone(cgrp); |
4014 | } | 3972 | } |
4015 | 3973 | ||
4016 | cgroup_lock_hierarchy(root); | ||
4017 | list_add(&cgrp->sibling, &cgrp->parent->children); | 3974 | list_add(&cgrp->sibling, &cgrp->parent->children); |
4018 | cgroup_unlock_hierarchy(root); | ||
4019 | root->number_of_cgroups++; | 3975 | root->number_of_cgroups++; |
4020 | 3976 | ||
4021 | err = cgroup_create_dir(cgrp, dentry, mode); | 3977 | err = cgroup_create_dir(cgrp, dentry, mode); |
@@ -4042,9 +3998,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
4042 | 3998 | ||
4043 | err_remove: | 3999 | err_remove: |
4044 | 4000 | ||
4045 | cgroup_lock_hierarchy(root); | ||
4046 | list_del(&cgrp->sibling); | 4001 | list_del(&cgrp->sibling); |
4047 | cgroup_unlock_hierarchy(root); | ||
4048 | root->number_of_cgroups--; | 4002 | root->number_of_cgroups--; |
4049 | 4003 | ||
4050 | err_destroy: | 4004 | err_destroy: |
@@ -4252,10 +4206,8 @@ again: | |||
4252 | list_del_init(&cgrp->release_list); | 4206 | list_del_init(&cgrp->release_list); |
4253 | raw_spin_unlock(&release_list_lock); | 4207 | raw_spin_unlock(&release_list_lock); |
4254 | 4208 | ||
4255 | cgroup_lock_hierarchy(cgrp->root); | ||
4256 | /* delete this cgroup from parent->children */ | 4209 | /* delete this cgroup from parent->children */ |
4257 | list_del_init(&cgrp->sibling); | 4210 | list_del_init(&cgrp->sibling); |
4258 | cgroup_unlock_hierarchy(cgrp->root); | ||
4259 | 4211 | ||
4260 | list_del_init(&cgrp->allcg_node); | 4212 | list_del_init(&cgrp->allcg_node); |
4261 | 4213 | ||
@@ -4329,8 +4281,6 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss) | |||
4329 | * need to invoke fork callbacks here. */ | 4281 | * need to invoke fork callbacks here. */ |
4330 | BUG_ON(!list_empty(&init_task.tasks)); | 4282 | BUG_ON(!list_empty(&init_task.tasks)); |
4331 | 4283 | ||
4332 | mutex_init(&ss->hierarchy_mutex); | ||
4333 | lockdep_set_class(&ss->hierarchy_mutex, &ss->subsys_key); | ||
4334 | ss->active = 1; | 4284 | ss->active = 1; |
4335 | 4285 | ||
4336 | /* this function shouldn't be used with modular subsystems, since they | 4286 | /* this function shouldn't be used with modular subsystems, since they |
@@ -4457,8 +4407,6 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss) | |||
4457 | } | 4407 | } |
4458 | write_unlock(&css_set_lock); | 4408 | write_unlock(&css_set_lock); |
4459 | 4409 | ||
4460 | mutex_init(&ss->hierarchy_mutex); | ||
4461 | lockdep_set_class(&ss->hierarchy_mutex, &ss->subsys_key); | ||
4462 | ss->active = 1; | 4410 | ss->active = 1; |
4463 | 4411 | ||
4464 | /* success! */ | 4412 | /* success! */ |