History

block: move set_task_ioprio to blk-ioc.c

Keep set_task_ioprio with the other low-level code that accesses the io_context structure.

Christoph Hellwig committed 4 years ago

Commit a411cd31 parent 091abcb3 files · +32 −36Browse files

Unified · Split

3 files
  1. block/blk-ioc.c +32 −2
  2. block/ioprio.c +0 −32
  3. include/linux/iocontext.h +0 −2
block/blk-ioc.c+32−2
@@ -8,6 +8,7 @@ · 7 unmodified lines
88 #include <linux/bio.h>
99 #include <linux/blkdev.h>
1010 #include <linux/slab.h>
11+#include <linux/security.h>
1112 #include <linux/sched/task.h>
1213
1314 #include "blk.h"
@@ -280,8 +281,8 @@ static struct io_context *create_task_io_context(struct task_struct *task, · 266 unmodified lines
280281 * This function always goes through task_lock() and it's better to use
281282 * %current->io_context + get_io_context() for %current.
282283 */
283−struct io_context *get_task_io_context(struct task_struct *task,
284− gfp_t gfp_flags, int node)
284+static struct io_context *get_task_io_context(struct task_struct *task,
285+ gfp_t gfp_flags, int node)
285286 {
286287 struct io_context *ioc;
287288
@@ -298,6 +299,35 @@ struct io_context *get_task_io_context(struct task_struct *task, · 10 unmodified lines
298299 return ioc;
299300 }
300301
302+int set_task_ioprio(struct task_struct *task, int ioprio)
303+{
304+ int err;
305+ struct io_context *ioc;
306+ const struct cred *cred = current_cred(), *tcred;
307+
308+ rcu_read_lock();
309+ tcred = __task_cred(task);
310+ if (!uid_eq(tcred->uid, cred->euid) &&
311+ !uid_eq(tcred->uid, cred->uid) && !capable(CAP_SYS_NICE)) {
312+ rcu_read_unlock();
313+ return -EPERM;
314+ }
315+ rcu_read_unlock();
316+
317+ err = security_task_setioprio(task, ioprio);
318+ if (err)
319+ return err;
320+
321+ ioc = get_task_io_context(task, GFP_ATOMIC, NUMA_NO_NODE);
322+ if (ioc) {
323+ ioc->ioprio = ioprio;
324+ put_io_context(ioc);
325+ }
326+
327+ return err;
328+}
329+EXPORT_SYMBOL_GPL(set_task_ioprio);
330+
301331 int __copy_io(unsigned long clone_flags, struct task_struct *tsk)
302332 {
303333 struct io_context *ioc = current->io_context;
block/ioprio.c+0−32
@@ -22,46 +22,14 @@ · 21 unmodified lines
2222 */
2323 #include <linux/gfp.h>
2424 #include <linux/kernel.h>
25−#include <linux/export.h>
2625 #include <linux/ioprio.h>
2726 #include <linux/cred.h>
2827 #include <linux/blkdev.h>
2928 #include <linux/capability.h>
30−#include <linux/sched/user.h>
31−#include <linux/sched/task.h>
3229 #include <linux/syscalls.h>
3330 #include <linux/security.h>
3431 #include <linux/pid_namespace.h>
3532
36−int set_task_ioprio(struct task_struct *task, int ioprio)
37−{
38− int err;
39− struct io_context *ioc;
40− const struct cred *cred = current_cred(), *tcred;
41−
42− rcu_read_lock();
43− tcred = __task_cred(task);
44− if (!uid_eq(tcred->uid, cred->euid) &&
45− !uid_eq(tcred->uid, cred->uid) && !capable(CAP_SYS_NICE)) {
46− rcu_read_unlock();
47− return -EPERM;
48− }
49− rcu_read_unlock();
50−
51− err = security_task_setioprio(task, ioprio);
52− if (err)
53− return err;
54−
55− ioc = get_task_io_context(task, GFP_ATOMIC, NUMA_NO_NODE);
56− if (ioc) {
57− ioc->ioprio = ioprio;
58− put_io_context(ioc);
59− }
60−
61− return err;
62−}
63−EXPORT_SYMBOL_GPL(set_task_ioprio);
64−
6533 int ioprio_check_cap(int ioprio)
6634 {
6735 int class = IOPRIO_PRIO_CLASS(ioprio);
include/linux/iocontext.h+0−2
@@ -116,8 +116,6 @@ struct task_struct; · 115 unmodified lines
116116 #ifdef CONFIG_BLOCK
117117 void put_io_context(struct io_context *ioc);
118118 void exit_io_context(struct task_struct *task);
119−struct io_context *get_task_io_context(struct task_struct *task,
120− gfp_t gfp_flags, int node);
121119 int __copy_io(unsigned long clone_flags, struct task_struct *tsk);
122120 static inline int copy_io(unsigned long clone_flags, struct task_struct *tsk)
123121 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t