Merge tag 'cputime-adjustment-cleanups' of git://git.kernel.org/pub/scm/linux/kernel...
[deliverable/linux.git] / fs / proc / base.c
index d295af993677dda290242adb5e0187deef1bcb7c..587631e1cd0631f4ba55892425f83f077091150f 100644 (file)
@@ -873,36 +873,36 @@ static const struct file_operations proc_environ_operations = {
        .release        = mem_release,
 };
 
-static ssize_t oom_adjust_read(struct file *file, char __user *buf,
-                               size_t count, loff_t *ppos)
+static ssize_t oom_adj_read(struct file *file, char __user *buf, size_t count,
+                           loff_t *ppos)
 {
        struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
        char buffer[PROC_NUMBUF];
+       int oom_adj = OOM_ADJUST_MIN;
        size_t len;
-       int oom_adjust = OOM_DISABLE;
        unsigned long flags;
 
        if (!task)
                return -ESRCH;
-
        if (lock_task_sighand(task, &flags)) {
-               oom_adjust = task->signal->oom_adj;
+               if (task->signal->oom_score_adj == OOM_SCORE_ADJ_MAX)
+                       oom_adj = OOM_ADJUST_MAX;
+               else
+                       oom_adj = (task->signal->oom_score_adj * -OOM_DISABLE) /
+                                 OOM_SCORE_ADJ_MAX;
                unlock_task_sighand(task, &flags);
        }
-
        put_task_struct(task);
-
-       len = snprintf(buffer, sizeof(buffer), "%i\n", oom_adjust);
-
+       len = snprintf(buffer, sizeof(buffer), "%d\n", oom_adj);
        return simple_read_from_buffer(buf, count, ppos, buffer, len);
 }
 
-static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
-                               size_t count, loff_t *ppos)
+static ssize_t oom_adj_write(struct file *file, const char __user *buf,
+                            size_t count, loff_t *ppos)
 {
        struct task_struct *task;
        char buffer[PROC_NUMBUF];
-       int oom_adjust;
+       int oom_adj;
        unsigned long flags;
        int err;
 
@@ -914,11 +914,11 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
                goto out;
        }
 
-       err = kstrtoint(strstrip(buffer), 0, &oom_adjust);
+       err = kstrtoint(strstrip(buffer), 0, &oom_adj);
        if (err)
                goto out;
-       if ((oom_adjust < OOM_ADJUST_MIN || oom_adjust > OOM_ADJUST_MAX) &&
-            oom_adjust != OOM_DISABLE) {
+       if ((oom_adj < OOM_ADJUST_MIN || oom_adj > OOM_ADJUST_MAX) &&
+            oom_adj != OOM_DISABLE) {
                err = -EINVAL;
                goto out;
        }
@@ -940,28 +940,30 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
                goto err_task_lock;
        }
 
-       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
+       /*
+        * Scale /proc/pid/oom_score_adj appropriately ensuring that a maximum
+        * value is always attainable.
+        */
+       if (oom_adj == OOM_ADJUST_MAX)
+               oom_adj = OOM_SCORE_ADJ_MAX;
+       else
+               oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
+
+       if (oom_adj < task->signal->oom_score_adj &&
+           !capable(CAP_SYS_RESOURCE)) {
                err = -EACCES;
                goto err_sighand;
        }
 
        /*
-        * Warn that /proc/pid/oom_adj is deprecated, see
-        * Documentation/feature-removal-schedule.txt.
+        * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
+        * /proc/pid/oom_score_adj instead.
         */
        printk_once(KERN_WARNING "%s (%d): /proc/%d/oom_adj is deprecated, please use /proc/%d/oom_score_adj instead.\n",
                  current->comm, task_pid_nr(current), task_pid_nr(task),
                  task_pid_nr(task));
-       task->signal->oom_adj = oom_adjust;
-       /*
-        * Scale /proc/pid/oom_score_adj appropriately ensuring that a maximum
-        * value is always attainable.
-        */
-       if (task->signal->oom_adj == OOM_ADJUST_MAX)
-               task->signal->oom_score_adj = OOM_SCORE_ADJ_MAX;
-       else
-               task->signal->oom_score_adj = (oom_adjust * OOM_SCORE_ADJ_MAX) /
-                                                               -OOM_DISABLE;
+
+       task->signal->oom_score_adj = oom_adj;
        trace_oom_score_adj_update(task);
 err_sighand:
        unlock_task_sighand(task, &flags);
@@ -972,9 +974,9 @@ out:
        return err < 0 ? err : count;
 }
 
-static const struct file_operations proc_oom_adjust_operations = {
-       .read           = oom_adjust_read,
-       .write          = oom_adjust_write,
+static const struct file_operations proc_oom_adj_operations = {
+       .read           = oom_adj_read,
+       .write          = oom_adj_write,
        .llseek         = generic_file_llseek,
 };
 
@@ -1051,15 +1053,7 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
        if (has_capability_noaudit(current, CAP_SYS_RESOURCE))
                task->signal->oom_score_adj_min = oom_score_adj;
        trace_oom_score_adj_update(task);
-       /*
-        * Scale /proc/pid/oom_adj appropriately ensuring that OOM_DISABLE is
-        * always attainable.
-        */
-       if (task->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
-               task->signal->oom_adj = OOM_DISABLE;
-       else
-               task->signal->oom_adj = (oom_score_adj * OOM_ADJUST_MAX) /
-                                                       OOM_SCORE_ADJ_MAX;
+
 err_sighand:
        unlock_task_sighand(task, &flags);
 err_task_lock:
@@ -1278,81 +1272,6 @@ static const struct file_operations proc_pid_sched_operations = {
 
 #endif
 
-#ifdef CONFIG_SCHED_AUTOGROUP
-/*
- * Print out autogroup related information:
- */
-static int sched_autogroup_show(struct seq_file *m, void *v)
-{
-       struct inode *inode = m->private;
-       struct task_struct *p;
-
-       p = get_proc_task(inode);
-       if (!p)
-               return -ESRCH;
-       proc_sched_autogroup_show_task(p, m);
-
-       put_task_struct(p);
-
-       return 0;
-}
-
-static ssize_t
-sched_autogroup_write(struct file *file, const char __user *buf,
-           size_t count, loff_t *offset)
-{
-       struct inode *inode = file->f_path.dentry->d_inode;
-       struct task_struct *p;
-       char buffer[PROC_NUMBUF];
-       int nice;
-       int err;
-
-       memset(buffer, 0, sizeof(buffer));
-       if (count > sizeof(buffer) - 1)
-               count = sizeof(buffer) - 1;
-       if (copy_from_user(buffer, buf, count))
-               return -EFAULT;
-
-       err = kstrtoint(strstrip(buffer), 0, &nice);
-       if (err < 0)
-               return err;
-
-       p = get_proc_task(inode);
-       if (!p)
-               return -ESRCH;
-
-       err = proc_sched_autogroup_set_nice(p, nice);
-       if (err)
-               count = err;
-
-       put_task_struct(p);
-
-       return count;
-}
-
-static int sched_autogroup_open(struct inode *inode, struct file *filp)
-{
-       int ret;
-
-       ret = single_open(filp, sched_autogroup_show, NULL);
-       if (!ret) {
-               struct seq_file *m = filp->private_data;
-
-               m->private = inode;
-       }
-       return ret;
-}
-
-static const struct file_operations proc_pid_sched_autogroup_operations = {
-       .open           = sched_autogroup_open,
-       .read           = seq_read,
-       .write          = sched_autogroup_write,
-       .llseek         = seq_lseek,
-       .release        = single_release,
-};
-
-#endif /* CONFIG_SCHED_AUTOGROUP */
-
 static ssize_t comm_write(struct file *file, const char __user *buf,
                                size_t count, loff_t *offset)
 {
@@ -1883,8 +1802,9 @@ static struct dentry *proc_map_files_lookup(struct inode *dir,
        if (!vma)
                goto out_no_vma;
 
-       result = proc_map_files_instantiate(dir, dentry, task,
-                       (void *)(unsigned long)vma->vm_file->f_mode);
+       if (vma->vm_file)
+               result = proc_map_files_instantiate(dir, dentry, task,
+                               (void *)(unsigned long)vma->vm_file->f_mode);
 
 out_no_vma:
        up_read(&mm->mmap_sem);
@@ -2371,7 +2291,8 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
        pid_t tgid = task_tgid_nr_ns(current, ns);
        char *name = ERR_PTR(-ENOENT);
        if (tgid) {
-               name = __getname();
+               /* 11 for max length of signed int in decimal + NULL term */
+               name = kmalloc(12, GFP_KERNEL);
                if (!name)
                        name = ERR_PTR(-ENOMEM);
                else
@@ -2386,7 +2307,7 @@ static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
 {
        char *s = nd_get_link(nd);
        if (!IS_ERR(s))
-               __putname(s);
+               kfree(s);
 }
 
 static const struct inode_operations proc_self_inode_operations = {
@@ -2661,9 +2582,6 @@ static const struct pid_entry tgid_base_stuff[] = {
        INF("limits",     S_IRUGO, proc_pid_limits),
 #ifdef CONFIG_SCHED_DEBUG
        REG("sched",      S_IRUGO|S_IWUSR, proc_pid_sched_operations),
-#endif
-#ifdef CONFIG_SCHED_AUTOGROUP
-       REG("autogroup",  S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
 #endif
        REG("comm",      S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
 #ifdef CONFIG_HAVE_ARCH_TRACEHOOK
@@ -2710,7 +2628,7 @@ static const struct pid_entry tgid_base_stuff[] = {
        REG("cgroup",  S_IRUGO, proc_cgroup_operations),
 #endif
        INF("oom_score",  S_IRUGO, proc_oom_score),
-       REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
+       REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
        REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
 #ifdef CONFIG_AUDITSYSCALL
        REG("loginuid",   S_IWUSR|S_IRUGO, proc_loginuid_operations),
@@ -3077,7 +2995,7 @@ static const struct pid_entry tid_base_stuff[] = {
        REG("cgroup",  S_IRUGO, proc_cgroup_operations),
 #endif
        INF("oom_score", S_IRUGO, proc_oom_score),
-       REG("oom_adj",   S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
+       REG("oom_adj",   S_IRUGO|S_IWUSR, proc_oom_adj_operations),
        REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
 #ifdef CONFIG_AUDITSYSCALL
        REG("loginuid",  S_IWUSR|S_IRUGO, proc_loginuid_operations),
This page took 0.029208 seconds and 5 git commands to generate.