Skip to content

Commit

Permalink
Revert "cgroup: remove redundant variable in cgroup_mount()"
Browse files Browse the repository at this point in the history
This reverts commit 0c7bf3e.

If there are child cgroups in the cgroupfs and then we umount it,
the superblock will be destroyed but the cgroup_root will be kept
around. When we mount it again, cgroup_mount() will find this
cgroup_root and allocate a new sb for it.

So with this commit we will be trapped in a dead loop in the case
described above, because kernfs_pin_sb() keeps returning NULL.

Currently I don't see how we can avoid using both pinned_sb and
new_sb, so just revert it.

Cc: Al Viro <[email protected]>
Reported-by: Andrey Wagin <[email protected]>
Signed-off-by: Zefan Li <[email protected]>
Signed-off-by: Tejun Heo <[email protected]>
  • Loading branch information
lizf-os authored and htejun committed Sep 26, 2014
1 parent 0c7bf3e commit e756c7b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions kernel/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,7 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,
struct dentry *dentry;
int ret;
int i;
bool new_sb;

/*
* The first time anyone tries to mount a cgroup, enable the list
Expand Down Expand Up @@ -1784,7 +1785,7 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,
* path is super cold. Let's just sleep a bit and retry.
*/
pinned_sb = kernfs_pin_sb(root->kf_root, NULL);
if (IS_ERR_OR_NULL(pinned_sb) ||
if (IS_ERR(pinned_sb) ||
!percpu_ref_tryget_live(&root->cgrp.self.refcnt)) {
mutex_unlock(&cgroup_mutex);
if (!IS_ERR_OR_NULL(pinned_sb))
Expand Down Expand Up @@ -1830,16 +1831,18 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,
return ERR_PTR(ret);

dentry = kernfs_mount(fs_type, flags, root->kf_root,
CGROUP_SUPER_MAGIC, NULL);
if (IS_ERR(dentry) || pinned_sb)
CGROUP_SUPER_MAGIC, &new_sb);
if (IS_ERR(dentry) || !new_sb)
cgroup_put(&root->cgrp);

/*
* If @pinned_sb, we're reusing an existing root and holding an
* extra ref on its sb. Mount is complete. Put the extra ref.
*/
if (pinned_sb)
if (pinned_sb) {
WARN_ON(new_sb);
deactivate_super(pinned_sb);
}

return dentry;
}
Expand Down

0 comments on commit e756c7b

Please sign in to comment.