arch/x86/oprofile/op_model_amd.c: fix op_amd_handle_ibs() return type
[safe/jmp/linux-2.6] / kernel / cgroup.c
index fc5e4a4..3737a68 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/cgroupstats.h>
 #include <linux/hash.h>
 #include <linux/namei.h>
+#include <linux/smp_lock.h>
 
 #include <asm/atomic.h>
 
@@ -842,6 +843,11 @@ static int parse_cgroupfs_options(char *data,
                                     struct cgroup_sb_opts *opts)
 {
        char *token, *o = data ?: "all";
+       unsigned long mask = (unsigned long)-1;
+
+#ifdef CONFIG_CPUSETS
+       mask = ~(1UL << cpuset_subsys_id);
+#endif
 
        opts->subsys_bits = 0;
        opts->flags = 0;
@@ -886,6 +892,15 @@ static int parse_cgroupfs_options(char *data,
                }
        }
 
+       /*
+        * Option noprefix was introduced just for backward compatibility
+        * with the old cpuset, so we allow noprefix only if mounting just
+        * the cpuset subsystem.
+        */
+       if (test_bit(ROOT_NOPREFIX, &opts->flags) &&
+           (opts->subsys_bits & mask))
+               return -EINVAL;
+
        /* We can't have an empty hierarchy */
        if (!opts->subsys_bits)
                return -EINVAL;
@@ -900,6 +915,7 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data)
        struct cgroup *cgrp = &root->top_cgroup;
        struct cgroup_sb_opts opts;
 
+       lock_kernel();
        mutex_lock(&cgrp->dentry->d_inode->i_mutex);
        mutex_lock(&cgroup_mutex);
 
@@ -915,18 +931,19 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data)
        }
 
        ret = rebind_subsystems(root, opts.subsys_bits);
+       if (ret)
+               goto out_unlock;
 
        /* (re)populate subsystem files */
-       if (!ret)
-               cgroup_populate_dir(cgrp);
+       cgroup_populate_dir(cgrp);
 
        if (opts.release_agent)
                strcpy(root->release_agent_path, opts.release_agent);
  out_unlock:
-       if (opts.release_agent)
-               kfree(opts.release_agent);
+       kfree(opts.release_agent);
        mutex_unlock(&cgroup_mutex);
        mutex_unlock(&cgrp->dentry->d_inode->i_mutex);
+       unlock_kernel();
        return ret;
 }
 
@@ -1027,15 +1044,13 @@ static int cgroup_get_sb(struct file_system_type *fs_type,
        /* First find the desired set of subsystems */
        ret = parse_cgroupfs_options(data, &opts);
        if (ret) {
-               if (opts.release_agent)
-                       kfree(opts.release_agent);
+               kfree(opts.release_agent);
                return ret;
        }
 
        root = kzalloc(sizeof(*root), GFP_KERNEL);
        if (!root) {
-               if (opts.release_agent)
-                       kfree(opts.release_agent);
+               kfree(opts.release_agent);
                return -ENOMEM;
        }
 
@@ -1135,8 +1150,7 @@ static int cgroup_get_sb(struct file_system_type *fs_type,
  free_cg_links:
        free_cg_links(&tmp_cg_links);
  drop_new_super:
-       up_write(&sb->s_umount);
-       deactivate_super(sb);
+       deactivate_locked_super(sb);
        return ret;
 }
 
@@ -1689,7 +1703,7 @@ static struct inode_operations cgroup_dir_inode_operations = {
        .rename = cgroup_rename,
 };
 
-static int cgroup_create_file(struct dentry *dentry, int mode,
+static int cgroup_create_file(struct dentry *dentry, mode_t mode,
                                struct super_block *sb)
 {
        static const struct dentry_operations cgroup_dops = {
@@ -1735,7 +1749,7 @@ static int cgroup_create_file(struct dentry *dentry, int mode,
  * @mode: mode to set on new directory.
  */
 static int cgroup_create_dir(struct cgroup *cgrp, struct dentry *dentry,
-                               int mode)
+                               mode_t mode)
 {
        struct dentry *parent;
        int error = 0;
@@ -1753,6 +1767,33 @@ static int cgroup_create_dir(struct cgroup *cgrp, struct dentry *dentry,
        return error;
 }
 
+/**
+ * cgroup_file_mode - deduce file mode of a control file
+ * @cft: the control file in question
+ *
+ * returns cft->mode if ->mode is not 0
+ * returns S_IRUGO|S_IWUSR if it has both a read and a write handler
+ * returns S_IRUGO if it has only a read handler
+ * returns S_IWUSR if it has only a write hander
+ */
+static mode_t cgroup_file_mode(const struct cftype *cft)
+{
+       mode_t mode = 0;
+
+       if (cft->mode)
+               return cft->mode;
+
+       if (cft->read || cft->read_u64 || cft->read_s64 ||
+           cft->read_map || cft->read_seq_string)
+               mode |= S_IRUGO;
+
+       if (cft->write || cft->write_u64 || cft->write_s64 ||
+           cft->write_string || cft->trigger)
+               mode |= S_IWUSR;
+
+       return mode;
+}
+
 int cgroup_add_file(struct cgroup *cgrp,
                       struct cgroup_subsys *subsys,
                       const struct cftype *cft)
@@ -1760,6 +1801,7 @@ int cgroup_add_file(struct cgroup *cgrp,
        struct dentry *dir = cgrp->dentry;
        struct dentry *dentry;
        int error;
+       mode_t mode;
 
        char name[MAX_CGROUP_TYPE_NAMELEN + MAX_CFTYPE_NAME + 2] = { 0 };
        if (subsys && !test_bit(ROOT_NOPREFIX, &cgrp->root->flags)) {
@@ -1770,7 +1812,8 @@ int cgroup_add_file(struct cgroup *cgrp,
        BUG_ON(!mutex_is_locked(&dir->d_inode->i_mutex));
        dentry = lookup_one_len(name, dir, strlen(name));
        if (!IS_ERR(dentry)) {
-               error = cgroup_create_file(dentry, 0644 | S_IFREG,
+               mode = cgroup_file_mode(cft);
+               error = cgroup_create_file(dentry, mode | S_IFREG,
                                                cgrp->root->sb);
                if (!error)
                        dentry->d_fsdata = (void *)cft;
@@ -2352,6 +2395,7 @@ static struct cftype files[] = {
                .write_u64 = cgroup_tasks_write,
                .release = cgroup_tasks_release,
                .private = FILE_TASKLIST,
+               .mode = S_IRUGO | S_IWUSR,
        },
 
        {
@@ -2452,7 +2496,7 @@ static void cgroup_unlock_hierarchy(struct cgroupfs_root *root)
  * Must be called with the mutex on the parent inode held
  */
 static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
-                            int mode)
+                            mode_t mode)
 {
        struct cgroup *cgrp;
        struct cgroupfs_root *root = parent->root;
@@ -3377,7 +3421,7 @@ unsigned short css_depth(struct cgroup_subsys_state *css)
 }
 
 bool css_is_ancestor(struct cgroup_subsys_state *child,
-                   struct cgroup_subsys_state *root)
+                   const struct cgroup_subsys_state *root)
 {
        struct css_id *child_id = rcu_dereference(child->id);
        struct css_id *root_id = rcu_dereference(root->id);