diff options
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r-- | kernel/cgroup.c | 116 |
1 files changed, 0 insertions, 116 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 00a884342d3d..2731d115d725 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -4630,122 +4630,6 @@ void cgroup_exit(struct task_struct *tsk, int run_callbacks) | |||
4630 | } | 4630 | } |
4631 | 4631 | ||
4632 | /** | 4632 | /** |
4633 | * cgroup_clone - clone the cgroup the given subsystem is attached to | ||
4634 | * @tsk: the task to be moved | ||
4635 | * @subsys: the given subsystem | ||
4636 | * @nodename: the name for the new cgroup | ||
4637 | * | ||
4638 | * Duplicate the current cgroup in the hierarchy that the given | ||
4639 | * subsystem is attached to, and move this task into the new | ||
4640 | * child. | ||
4641 | */ | ||
4642 | int cgroup_clone(struct task_struct *tsk, struct cgroup_subsys *subsys, | ||
4643 | char *nodename) | ||
4644 | { | ||
4645 | struct dentry *dentry; | ||
4646 | int ret = 0; | ||
4647 | struct cgroup *parent, *child; | ||
4648 | struct inode *inode; | ||
4649 | struct css_set *cg; | ||
4650 | struct cgroupfs_root *root; | ||
4651 | struct cgroup_subsys *ss; | ||
4652 | |||
4653 | /* We shouldn't be called by an unregistered subsystem */ | ||
4654 | BUG_ON(!subsys->active); | ||
4655 | |||
4656 | /* First figure out what hierarchy and cgroup we're dealing | ||
4657 | * with, and pin them so we can drop cgroup_mutex */ | ||
4658 | mutex_lock(&cgroup_mutex); | ||
4659 | again: | ||
4660 | root = subsys->root; | ||
4661 | if (root == &rootnode) { | ||
4662 | mutex_unlock(&cgroup_mutex); | ||
4663 | return 0; | ||
4664 | } | ||
4665 | |||
4666 | /* Pin the hierarchy */ | ||
4667 | if (!atomic_inc_not_zero(&root->sb->s_active)) { | ||
4668 | /* We race with the final deactivate_super() */ | ||
4669 | mutex_unlock(&cgroup_mutex); | ||
4670 | return 0; | ||
4671 | } | ||
4672 | |||
4673 | /* Keep the cgroup alive */ | ||
4674 | task_lock(tsk); | ||
4675 | parent = task_cgroup(tsk, subsys->subsys_id); | ||
4676 | cg = tsk->cgroups; | ||
4677 | get_css_set(cg); | ||
4678 | task_unlock(tsk); | ||
4679 | |||
4680 | mutex_unlock(&cgroup_mutex); | ||
4681 | |||
4682 | /* Now do the VFS work to create a cgroup */ | ||
4683 | inode = parent->dentry->d_inode; | ||
4684 | |||
4685 | /* Hold the parent directory mutex across this operation to | ||
4686 | * stop anyone else deleting the new cgroup */ | ||
4687 | mutex_lock(&inode->i_mutex); | ||
4688 | dentry = lookup_one_len(nodename, parent->dentry, strlen(nodename)); | ||
4689 | if (IS_ERR(dentry)) { | ||
4690 | printk(KERN_INFO | ||
4691 | "cgroup: Couldn't allocate dentry for %s: %ld\n", nodename, | ||
4692 | PTR_ERR(dentry)); | ||
4693 | ret = PTR_ERR(dentry); | ||
4694 | goto out_release; | ||
4695 | } | ||
4696 | |||
4697 | /* Create the cgroup directory, which also creates the cgroup */ | ||
4698 | ret = vfs_mkdir(inode, dentry, 0755); | ||
4699 | child = __d_cgrp(dentry); | ||
4700 | dput(dentry); | ||
4701 | if (ret) { | ||
4702 | printk(KERN_INFO | ||
4703 | "Failed to create cgroup %s: %d\n", nodename, | ||
4704 | ret); | ||
4705 | goto out_release; | ||
4706 | } | ||
4707 | |||
4708 | /* The cgroup now exists. Retake cgroup_mutex and check | ||
4709 | * that we're still in the same state that we thought we | ||
4710 | * were. */ | ||
4711 | mutex_lock(&cgroup_mutex); | ||
4712 | if ((root != subsys->root) || | ||
4713 | (parent != task_cgroup(tsk, subsys->subsys_id))) { | ||
4714 | /* Aargh, we raced ... */ | ||
4715 | mutex_unlock(&inode->i_mutex); | ||
4716 | put_css_set(cg); | ||
4717 | |||
4718 | deactivate_super(root->sb); | ||
4719 | /* The cgroup is still accessible in the VFS, but | ||
4720 | * we're not going to try to rmdir() it at this | ||
4721 | * point. */ | ||
4722 | printk(KERN_INFO | ||
4723 | "Race in cgroup_clone() - leaking cgroup %s\n", | ||
4724 | nodename); | ||
4725 | goto again; | ||
4726 | } | ||
4727 | |||
4728 | /* do any required auto-setup */ | ||
4729 | for_each_subsys(root, ss) { | ||
4730 | if (ss->post_clone) | ||
4731 | ss->post_clone(ss, child); | ||
4732 | } | ||
4733 | |||
4734 | /* All seems fine. Finish by moving the task into the new cgroup */ | ||
4735 | ret = cgroup_attach_task(child, tsk); | ||
4736 | mutex_unlock(&cgroup_mutex); | ||
4737 | |||
4738 | out_release: | ||
4739 | mutex_unlock(&inode->i_mutex); | ||
4740 | |||
4741 | mutex_lock(&cgroup_mutex); | ||
4742 | put_css_set(cg); | ||
4743 | mutex_unlock(&cgroup_mutex); | ||
4744 | deactivate_super(root->sb); | ||
4745 | return ret; | ||
4746 | } | ||
4747 | |||
4748 | /** | ||
4749 | * cgroup_is_descendant - see if @cgrp is a descendant of @task's cgrp | 4633 | * cgroup_is_descendant - see if @cgrp is a descendant of @task's cgrp |
4750 | * @cgrp: the cgroup in question | 4634 | * @cgrp: the cgroup in question |
4751 | * @task: the task in question | 4635 | * @task: the task in question |