]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/cgroup.c
memcontrol: move oom task exclusion to tasklist scan
[linux-2.6-omap-h63xx.git] / kernel / cgroup.c
index 3fe21e19c96e3a51adfa6c462f188bdf6ca407b7..4d67a39c58a825c59c8847a82cc214c1894a8aa7 100644 (file)
@@ -1,6 +1,4 @@
 /*
- *  kernel/cgroup.c
- *
  *  Generic process-grouping system.
  *
  *  Based originally on the cpuset system, extracted by Paul Menage
@@ -143,7 +141,7 @@ enum {
        ROOT_NOPREFIX, /* mounted subsystems have no named prefix */
 };
 
-inline int cgroup_is_releasable(const struct cgroup *cgrp)
+static int cgroup_is_releasable(const struct cgroup *cgrp)
 {
        const int bits =
                (1 << CGRP_RELEASABLE) |
@@ -151,7 +149,7 @@ inline int cgroup_is_releasable(const struct cgroup *cgrp)
        return (cgrp->flags & bits) == bits;
 }
 
-inline int notify_on_release(const struct cgroup *cgrp)
+static int notify_on_release(const struct cgroup *cgrp)
 {
        return test_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
 }
@@ -593,6 +591,7 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode)
        /* is dentry a directory ? if so, kfree() associated cgroup */
        if (S_ISDIR(inode->i_mode)) {
                struct cgroup *cgrp = dentry->d_fsdata;
+               struct cgroup_subsys *ss;
                BUG_ON(!(cgroup_is_removed(cgrp)));
                /* It's possible for external users to be holding css
                 * reference counts on a cgroup; css_put() needs to
@@ -601,6 +600,23 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode)
                 * queue the cgroup to be handled by the release
                 * agent */
                synchronize_rcu();
+
+               mutex_lock(&cgroup_mutex);
+               /*
+                * Release the subsystem state objects.
+                */
+               for_each_subsys(cgrp->root, ss) {
+                       if (cgrp->subsys[ss->subsys_id])
+                               ss->destroy(ss, cgrp);
+               }
+
+               cgrp->root->number_of_cgroups--;
+               mutex_unlock(&cgroup_mutex);
+
+               /* Drop the active superblock reference that we took when we
+                * created the cgroup */
+               deactivate_super(cgrp->root->sb);
+
                kfree(cgrp);
        }
        iput(inode);
@@ -1183,9 +1199,8 @@ static int attach_task(struct cgroup *cgrp, struct task_struct *tsk)
        for_each_subsys(root, ss) {
                if (ss->can_attach) {
                        retval = ss->can_attach(ss, cgrp, tsk);
-                       if (retval) {
+                       if (retval)
                                return retval;
-                       }
                }
        }
 
@@ -1194,9 +1209,8 @@ static int attach_task(struct cgroup *cgrp, struct task_struct *tsk)
         * based on its final set of cgroups
         */
        newcg = find_css_set(cg, cgrp);
-       if (!newcg) {
+       if (!newcg)
                return -ENOMEM;
-       }
 
        task_lock(tsk);
        if (tsk->flags & PF_EXITING) {
@@ -1216,9 +1230,8 @@ static int attach_task(struct cgroup *cgrp, struct task_struct *tsk)
        write_unlock(&css_set_lock);
 
        for_each_subsys(root, ss) {
-               if (ss->attach) {
+               if (ss->attach)
                        ss->attach(ss, cgrp, oldcgrp, tsk);
-               }
        }
        set_bit(CGRP_RELEASABLE, &oldcgrp->flags);
        synchronize_rcu();
@@ -1331,9 +1344,14 @@ static ssize_t cgroup_common_file_write(struct cgroup *cgrp,
                goto out1;
        }
        buffer[nbytes] = 0;     /* nul-terminate */
+       strstrip(buffer);       /* strip -just- trailing whitespace */
 
        mutex_lock(&cgroup_mutex);
 
+       /*
+        * This was already checked for in cgroup_file_write(), but
+        * check again now we're holding cgroup_mutex.
+        */
        if (cgroup_is_removed(cgrp)) {
                retval = -ENODEV;
                goto out2;
@@ -1351,24 +1369,9 @@ static ssize_t cgroup_common_file_write(struct cgroup *cgrp,
                        clear_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
                break;
        case FILE_RELEASE_AGENT:
-       {
-               struct cgroupfs_root *root = cgrp->root;
-               /* Strip trailing newline */
-               if (nbytes && (buffer[nbytes-1] == '\n')) {
-                       buffer[nbytes-1] = 0;
-               }
-               if (nbytes < sizeof(root->release_agent_path)) {
-                       /* We never write anything other than '\0'
-                        * into the last char of release_agent_path,
-                        * so it always remains a NUL-terminated
-                        * string */
-                       strncpy(root->release_agent_path, buffer, nbytes);
-                       root->release_agent_path[nbytes] = 0;
-               } else {
-                       retval = -ENOSPC;
-               }
+               BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
+               strcpy(cgrp->root->release_agent_path, buffer);
                break;
-       }
        default:
                retval = -EINVAL;
                goto out2;
@@ -1389,7 +1392,7 @@ static ssize_t cgroup_file_write(struct file *file, const char __user *buf,
        struct cftype *cft = __d_cft(file->f_dentry);
        struct cgroup *cgrp = __d_cgrp(file->f_dentry->d_parent);
 
-       if (!cft)
+       if (!cft || cgroup_is_removed(cgrp))
                return -ENODEV;
        if (cft->write)
                return cft->write(cgrp, cft, file, buf, nbytes, ppos);
@@ -1459,7 +1462,7 @@ static ssize_t cgroup_file_read(struct file *file, char __user *buf,
        struct cftype *cft = __d_cft(file->f_dentry);
        struct cgroup *cgrp = __d_cgrp(file->f_dentry->d_parent);
 
-       if (!cft)
+       if (!cft || cgroup_is_removed(cgrp))
                return -ENODEV;
 
        if (cft->read)
@@ -2128,9 +2131,8 @@ static inline int cgroup_has_css_refs(struct cgroup *cgrp)
                 * matter, since it can only happen if the cgroup
                 * has been deleted and hence no longer needs the
                 * release agent to be called anyway. */
-               if (css && atomic_read(&css->refcnt)) {
+               if (css && atomic_read(&css->refcnt))
                        return 1;
-               }
        }
        return 0;
 }
@@ -2140,7 +2142,6 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry)
        struct cgroup *cgrp = dentry->d_fsdata;
        struct dentry *d;
        struct cgroup *parent;
-       struct cgroup_subsys *ss;
        struct super_block *sb;
        struct cgroupfs_root *root;
 
@@ -2165,11 +2166,6 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry)
                return -EBUSY;
        }
 
-       for_each_subsys(root, ss) {
-               if (cgrp->subsys[ss->subsys_id])
-                       ss->destroy(ss, cgrp);
-       }
-
        spin_lock(&release_list_lock);
        set_bit(CGRP_REMOVED, &cgrp->flags);
        if (!list_empty(&cgrp->release_list))
@@ -2184,15 +2180,11 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry)
 
        cgroup_d_remove_dir(d);
        dput(d);
-       root->number_of_cgroups--;
 
        set_bit(CGRP_RELEASABLE, &parent->flags);
        check_for_release(parent);
 
        mutex_unlock(&cgroup_mutex);
-       /* Drop the active superblock reference that we took when we
-        * created the cgroup */
-       deactivate_super(sb);
        return 0;
 }
 
@@ -2200,7 +2192,8 @@ static void cgroup_init_subsys(struct cgroup_subsys *ss)
 {
        struct cgroup_subsys_state *css;
        struct list_head *l;
-       printk(KERN_ERR "Initializing cgroup subsys %s\n", ss->name);
+
+       printk(KERN_INFO "Initializing cgroup subsys %s\n", ss->name);
 
        /* Create the top cgroup state for this subsystem */
        ss->root = &rootnode;
@@ -2273,7 +2266,7 @@ int __init cgroup_init_early(void)
                BUG_ON(!ss->create);
                BUG_ON(!ss->destroy);
                if (ss->subsys_id != i) {
-                       printk(KERN_ERR "Subsys %s id == %d\n",
+                       printk(KERN_ERR "cgroup: Subsys %s id == %d\n",
                               ss->name, ss->subsys_id);
                        BUG();
                }
@@ -2605,7 +2598,7 @@ int cgroup_clone(struct task_struct *tsk, struct cgroup_subsys *subsys)
        dentry = lookup_one_len(nodename, parent->dentry, strlen(nodename));
        if (IS_ERR(dentry)) {
                printk(KERN_INFO
-                      "Couldn't allocate dentry for %s: %ld\n", nodename,
+                      "cgroup: Couldn't allocate dentry for %s: %ld\n", nodename,
                       PTR_ERR(dentry));
                ret = PTR_ERR(dentry);
                goto out_release;