Merge branch 'for-3.10-fixes' into for-3.11
authorTejun Heo <tj@kernel.org>
Fri, 24 May 2013 01:53:09 +0000 (10:53 +0900)
committerTejun Heo <tj@kernel.org>
Fri, 24 May 2013 01:53:09 +0000 (10:53 +0900)
Merging to receive 7805d000db ("cgroup: fix a subtle bug in descendant
pre-order walk") so that further iterator updates can build upon it.

Signed-off-by: Tejun Heo <tj@kernel.org>
1  2 
include/linux/cgroup.h
kernel/cgroup.c

diff --combined include/linux/cgroup.h
index 4f6f5138c340da971c35858a47ee55db6405980d,8bda1294c035b24912a3da178ebc2c8e1cd5f827..1df5f699be615a82be9089df82b783413c9d47f0
@@@ -542,8 -542,6 +542,8 @@@ int cgroup_is_removed(const struct cgro
  bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor);
  
  int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen);
 +int task_cgroup_path_from_hierarchy(struct task_struct *task, int hierarchy_id,
 +                                  char *buf, size_t buflen);
  
  int cgroup_task_count(const struct cgroup *cgrp);
  
@@@ -709,7 -707,7 +709,7 @@@ struct cgroup *cgroup_rightmost_descend
   *
   * If a subsystem synchronizes against the parent in its ->css_online() and
   * before starting iterating, and synchronizes against @pos on each
-  * iteration, any descendant cgroup which finished ->css_offline() is
+  * iteration, any descendant cgroup which finished ->css_online() is
   * guaranteed to be visible in the future iterations.
   *
   * In other words, the following guarantees that a descendant can't escape
@@@ -840,6 -838,8 +840,6 @@@ static inline void cgroup_fork(struct t
  static inline void cgroup_post_fork(struct task_struct *p) {}
  static inline void cgroup_exit(struct task_struct *p, int callbacks) {}
  
 -static inline void cgroup_lock(void) {}
 -static inline void cgroup_unlock(void) {}
  static inline int cgroupstats_build(struct cgroupstats *stats,
                                        struct dentry *dentry)
  {
diff --combined kernel/cgroup.c
index 6b2b1d945df2c4fd6a3b7334aabfcc72faf7d16e,31e9ef3190709da16828f8f11bf55b3d45f71af8..a19419f4af1a419d0c91faad08d8ffd9ae649e1c
@@@ -189,12 -189,9 +189,12 @@@ struct cgroup_event 
  static LIST_HEAD(roots);
  static int root_count;
  
 -static DEFINE_IDA(hierarchy_ida);
 -static int next_hierarchy_id;
 -static DEFINE_SPINLOCK(hierarchy_id_lock);
 +/*
 + * Hierarchy ID allocation and mapping.  It follows the same exclusion
 + * rules as other root ops - both cgroup_mutex and cgroup_root_mutex for
 + * writes, either for reads.
 + */
 +static DEFINE_IDR(cgroup_hierarchy_idr);
  
  /* dummytop is a shorthand for the dummy hierarchy's top cgroup */
  #define dummytop (&rootnode.top_cgroup)
@@@ -1429,30 -1426,29 +1429,30 @@@ static void init_cgroup_root(struct cgr
        list_add_tail(&cgrp->allcg_node, &root->allcg_list);
  }
  
 -static bool init_root_id(struct cgroupfs_root *root)
 +static int cgroup_init_root_id(struct cgroupfs_root *root)
  {
 -      int ret = 0;
 +      int id;
  
 -      do {
 -              if (!ida_pre_get(&hierarchy_ida, GFP_KERNEL))
 -                      return false;
 -              spin_lock(&hierarchy_id_lock);
 -              /* Try to allocate the next unused ID */
 -              ret = ida_get_new_above(&hierarchy_ida, next_hierarchy_id,
 -                                      &root->hierarchy_id);
 -              if (ret == -ENOSPC)
 -                      /* Try again starting from 0 */
 -                      ret = ida_get_new(&hierarchy_ida, &root->hierarchy_id);
 -              if (!ret) {
 -                      next_hierarchy_id = root->hierarchy_id + 1;
 -              } else if (ret != -EAGAIN) {
 -                      /* Can only get here if the 31-bit IDR is full ... */
 -                      BUG_ON(ret);
 -              }
 -              spin_unlock(&hierarchy_id_lock);
 -      } while (ret);
 -      return true;
 +      lockdep_assert_held(&cgroup_mutex);
 +      lockdep_assert_held(&cgroup_root_mutex);
 +
 +      id = idr_alloc_cyclic(&cgroup_hierarchy_idr, root, 2, 0, GFP_KERNEL);
 +      if (id < 0)
 +              return id;
 +
 +      root->hierarchy_id = id;
 +      return 0;
 +}
 +
 +static void cgroup_exit_root_id(struct cgroupfs_root *root)
 +{
 +      lockdep_assert_held(&cgroup_mutex);
 +      lockdep_assert_held(&cgroup_root_mutex);
 +
 +      if (root->hierarchy_id) {
 +              idr_remove(&cgroup_hierarchy_idr, root->hierarchy_id);
 +              root->hierarchy_id = 0;
 +      }
  }
  
  static int cgroup_test_super(struct super_block *sb, void *data)
@@@ -1486,6 -1482,10 +1486,6 @@@ static struct cgroupfs_root *cgroup_roo
        if (!root)
                return ERR_PTR(-ENOMEM);
  
 -      if (!init_root_id(root)) {
 -              kfree(root);
 -              return ERR_PTR(-ENOMEM);
 -      }
        init_cgroup_root(root);
  
        root->subsys_mask = opts->subsys_mask;
        return root;
  }
  
 -static void cgroup_drop_root(struct cgroupfs_root *root)
 +static void cgroup_free_root(struct cgroupfs_root *root)
  {
 -      if (!root)
 -              return;
 +      if (root) {
 +              /* hierarhcy ID shoulid already have been released */
 +              WARN_ON_ONCE(root->hierarchy_id);
  
 -      BUG_ON(!root->hierarchy_id);
 -      spin_lock(&hierarchy_id_lock);
 -      ida_remove(&hierarchy_ida, root->hierarchy_id);
 -      spin_unlock(&hierarchy_id_lock);
 -      ida_destroy(&root->cgroup_ida);
 -      kfree(root);
 +              ida_destroy(&root->cgroup_ida);
 +              kfree(root);
 +      }
  }
  
  static int cgroup_set_super(struct super_block *sb, void *data)
@@@ -1595,7 -1597,7 +1595,7 @@@ static struct dentry *cgroup_mount(stru
        sb = sget(fs_type, cgroup_test_super, cgroup_set_super, 0, &opts);
        if (IS_ERR(sb)) {
                ret = PTR_ERR(sb);
 -              cgroup_drop_root(opts.new_root);
 +              cgroup_free_root(opts.new_root);
                goto drop_modules;
        }
  
                if (ret)
                        goto unlock_drop;
  
 +              ret = cgroup_init_root_id(root);
 +              if (ret)
 +                      goto unlock_drop;
 +
                ret = rebind_subsystems(root, root->subsys_mask);
                if (ret == -EBUSY) {
                        free_cg_links(&tmp_cg_links);
                 * We re-used an existing hierarchy - the new root (if
                 * any) is not needed
                 */
 -              cgroup_drop_root(opts.new_root);
 +              cgroup_free_root(opts.new_root);
  
                if (((root->flags | opts.flags) & CGRP_ROOT_SANE_BEHAVIOR) &&
                    root->flags != opts.flags) {
        return dget(sb->s_root);
  
   unlock_drop:
 +      cgroup_exit_root_id(root);
        mutex_unlock(&cgroup_root_mutex);
        mutex_unlock(&cgroup_mutex);
        mutex_unlock(&inode->i_mutex);
@@@ -1757,15 -1754,13 +1757,15 @@@ static void cgroup_kill_sb(struct super
                root_count--;
        }
  
 +      cgroup_exit_root_id(root);
 +
        mutex_unlock(&cgroup_root_mutex);
        mutex_unlock(&cgroup_mutex);
  
        simple_xattrs_free(&cgrp->xattrs);
  
        kill_litter_super(sb);
 -      cgroup_drop_root(root);
 +      cgroup_free_root(root);
  }
  
  static struct file_system_type cgroup_fs_type = {
  }
  EXPORT_SYMBOL_GPL(cgroup_path);
  
 +/**
 + * task_cgroup_path_from_hierarchy - cgroup path of a task on a hierarchy
 + * @task: target task
 + * @hierarchy_id: the hierarchy to look up @task's cgroup from
 + * @buf: the buffer to write the path into
 + * @buflen: the length of the buffer
 + *
 + * Determine @task's cgroup on the hierarchy specified by @hierarchy_id and
 + * copy its path into @buf.  This function grabs cgroup_mutex and shouldn't
 + * be used inside locks used by cgroup controller callbacks.
 + */
 +int task_cgroup_path_from_hierarchy(struct task_struct *task, int hierarchy_id,
 +                                  char *buf, size_t buflen)
 +{
 +      struct cgroupfs_root *root;
 +      struct cgroup *cgrp = NULL;
 +      int ret = -ENOENT;
 +
 +      mutex_lock(&cgroup_mutex);
 +
 +      root = idr_find(&cgroup_hierarchy_idr, hierarchy_id);
 +      if (root) {
 +              cgrp = task_cgroup_from_root(task, root);
 +              ret = cgroup_path(cgrp, buf, buflen);
 +      }
 +
 +      mutex_unlock(&cgroup_mutex);
 +
 +      return ret;
 +}
 +EXPORT_SYMBOL_GPL(task_cgroup_path_from_hierarchy);
 +
  /*
   * Control Group taskset
   */
@@@ -2736,13 -2699,14 +2736,14 @@@ static int cgroup_add_file(struct cgrou
                goto out;
        }
  
+       cfe->type = (void *)cft;
+       cfe->dentry = dentry;
+       dentry->d_fsdata = cfe;
+       simple_xattrs_init(&cfe->xattrs);
        mode = cgroup_file_mode(cft);
        error = cgroup_create_file(dentry, mode | S_IFREG, cgrp->root->sb);
        if (!error) {
-               cfe->type = (void *)cft;
-               cfe->dentry = dentry;
-               dentry->d_fsdata = cfe;
-               simple_xattrs_init(&cfe->xattrs);
                list_add_tail(&cfe->node, &parent->files);
                cfe = NULL;
        }
@@@ -2990,11 -2954,8 +2991,8 @@@ struct cgroup *cgroup_next_descendant_p
        WARN_ON_ONCE(!rcu_read_lock_held());
  
        /* if first iteration, pretend we just visited @cgroup */
-       if (!pos) {
-               if (list_empty(&cgroup->children))
-                       return NULL;
+       if (!pos)
                pos = cgroup;
-       }
  
        /* visit the first child if exists */
        next = list_first_or_null_rcu(&pos->children, struct cgroup, sibling);
                return next;
  
        /* no child, visit my or the closest ancestor's next sibling */
-       do {
+       while (pos != cgroup) {
                next = list_entry_rcu(pos->sibling.next, struct cgroup,
                                      sibling);
                if (&next->sibling != &pos->parent->children)
                        return next;
  
                pos = pos->parent;
-       } while (pos != cgroup);
+       }
  
        return NULL;
  }
@@@ -4679,15 -4640,7 +4677,15 @@@ int __init cgroup_init(void
        /* Add init_css_set to the hash table */
        key = css_set_hash(init_css_set.subsys);
        hash_add(css_set_table, &init_css_set.hlist, key);
 -      BUG_ON(!init_root_id(&rootnode));
 +
 +      /* allocate id for the dummy hierarchy */
 +      mutex_lock(&cgroup_mutex);
 +      mutex_lock(&cgroup_root_mutex);
 +
 +      BUG_ON(cgroup_init_root_id(&rootnode));
 +
 +      mutex_unlock(&cgroup_root_mutex);
 +      mutex_unlock(&cgroup_mutex);
  
        cgroup_kobj = kobject_create_and_add("cgroup", fs_kobj);
        if (!cgroup_kobj) {
This page took 0.039124 seconds and 5 git commands to generate.