cifs: ensure that srv_mutex is held when dealing with ssocket pointer
[linux-3.10.git] / fs / ioprio.c
index c7c0b28..e50170c 100644 (file)
@@ -19,7 +19,9 @@
  * See also Documentation/block/ioprio.txt
  *
  */
+#include <linux/gfp.h>
 #include <linux/kernel.h>
+#include <linux/export.h>
 #include <linux/ioprio.h>
 #include <linux/blkdev.h>
 #include <linux/capability.h>
@@ -35,8 +37,8 @@ int set_task_ioprio(struct task_struct *task, int ioprio)
 
        rcu_read_lock();
        tcred = __task_cred(task);
-       if (tcred->uid != cred->euid &&
-           tcred->uid != cred->uid && !capable(CAP_SYS_NICE)) {
+       if (!uid_eq(tcred->uid, cred->euid) &&
+           !uid_eq(tcred->uid, cred->uid) && !capable(CAP_SYS_NICE)) {
                rcu_read_unlock();
                return -EPERM;
        }
@@ -46,28 +48,12 @@ int set_task_ioprio(struct task_struct *task, int ioprio)
        if (err)
                return err;
 
-       task_lock(task);
-       do {
-               ioc = task->io_context;
-               /* see wmb() in current_io_context() */
-               smp_read_barrier_depends();
-               if (ioc)
-                       break;
-
-               ioc = alloc_io_context(GFP_ATOMIC, -1);
-               if (!ioc) {
-                       err = -ENOMEM;
-                       break;
-               }
-               task->io_context = ioc;
-       } while (1);
-
-       if (!err) {
+       ioc = get_task_io_context(task, GFP_ATOMIC, NUMA_NO_NODE);
+       if (ioc) {
                ioc->ioprio = ioprio;
-               ioc->ioprio_changed = 1;
+               put_io_context(ioc);
        }
 
-       task_unlock(task);
        return err;
 }
 EXPORT_SYMBOL_GPL(set_task_ioprio);
@@ -79,6 +65,7 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
        struct task_struct *p, *g;
        struct user_struct *user;
        struct pid *pgrp;
+       kuid_t uid;
        int ret;
 
        switch (class) {
@@ -102,12 +89,7 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
        }
 
        ret = -ESRCH;
-       /*
-        * We want IOPRIO_WHO_PGRP/IOPRIO_WHO_USER to be "atomic",
-        * so we can't use rcu_read_lock(). See re-copy of ->ioprio
-        * in copy_process().
-        */
-       read_lock(&tasklist_lock);
+       rcu_read_lock();
        switch (which) {
                case IOPRIO_WHO_PROCESS:
                        if (!who)
@@ -129,16 +111,19 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
                        } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
                        break;
                case IOPRIO_WHO_USER:
+                       uid = make_kuid(current_user_ns(), who);
+                       if (!uid_valid(uid))
+                               break;
                        if (!who)
                                user = current_user();
                        else
-                               user = find_user(who);
+                               user = find_user(uid);
 
                        if (!user)
                                break;
 
                        do_each_thread(g, p) {
-                               if (__task_cred(p)->uid != who)
+                               if (!uid_eq(task_uid(p), uid))
                                        continue;
                                ret = set_task_ioprio(p, ioprio);
                                if (ret)
@@ -152,7 +137,7 @@ free_uid:
                        ret = -EINVAL;
        }
 
-       read_unlock(&tasklist_lock);
+       rcu_read_unlock();
        return ret;
 }
 
@@ -193,10 +178,11 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who)
        struct task_struct *g, *p;
        struct user_struct *user;
        struct pid *pgrp;
+       kuid_t uid;
        int ret = -ESRCH;
        int tmpio;
 
-       read_lock(&tasklist_lock);
+       rcu_read_lock();
        switch (which) {
                case IOPRIO_WHO_PROCESS:
                        if (!who)
@@ -222,16 +208,17 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who)
                        } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
                        break;
                case IOPRIO_WHO_USER:
+                       uid = make_kuid(current_user_ns(), who);
                        if (!who)
                                user = current_user();
                        else
-                               user = find_user(who);
+                               user = find_user(uid);
 
                        if (!user)
                                break;
 
                        do_each_thread(g, p) {
-                               if (__task_cred(p)->uid != user->uid)
+                               if (!uid_eq(task_uid(p), user->uid))
                                        continue;
                                tmpio = get_task_ioprio(p);
                                if (tmpio < 0)
@@ -249,6 +236,6 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who)
                        ret = -EINVAL;
        }
 
-       read_unlock(&tasklist_lock);
+       rcu_read_unlock();
        return ret;
 }