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
8#include <linux/bio.h>8#include <linux/bio.h>
9#include <linux/blkdev.h>9#include <linux/blkdev.h>
10#include <linux/slab.h>10#include <linux/slab.h>
11#include <linux/security.h>
11#include <linux/sched/task.h>12#include <linux/sched/task.h>
12 13
13#include "blk.h"14#include "blk.h"
@@ -280,8 +281,8 @@ static struct io_context *create_task_io_context(struct task_struct *task, · 266 unmodified lines
280 * This function always goes through task_lock() and it's better to use281 * This function always goes through task_lock() and it's better to use
281 * %current->io_context + get_io_context() for %current.282 * %current->io_context + get_io_context() for %current.
282 */283 */
283struct io_context *get_task_io_context(struct task_struct *task,284static struct io_context *get_task_io_context(struct task_struct *task,
284 gfp_t gfp_flags, int node)285 gfp_t gfp_flags, int node)
285{286{
286 struct io_context *ioc;287 struct io_context *ioc;
287 288
@@ -298,6 +299,35 @@ struct io_context *get_task_io_context(struct task_struct *task, · 10 unmodified lines
298 return ioc;299 return ioc;
299}300}
300 301
302int 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}
329EXPORT_SYMBOL_GPL(set_task_ioprio);
330
301int __copy_io(unsigned long clone_flags, struct task_struct *tsk)331int __copy_io(unsigned long clone_flags, struct task_struct *tsk)
302{332{
303 struct io_context *ioc = current->io_context;333 struct io_context *ioc = current->io_context;
block/ioprio.c+0−32
@@ -22,46 +22,14 @@ · 21 unmodified lines
22 */22 */
23#include <linux/gfp.h>23#include <linux/gfp.h>
24#include <linux/kernel.h>24#include <linux/kernel.h>
25#include <linux/export.h>
26#include <linux/ioprio.h>25#include <linux/ioprio.h>
27#include <linux/cred.h>26#include <linux/cred.h>
28#include <linux/blkdev.h>27#include <linux/blkdev.h>
29#include <linux/capability.h>28#include <linux/capability.h>
30#include <linux/sched/user.h>
31#include <linux/sched/task.h>
32#include <linux/syscalls.h>29#include <linux/syscalls.h>
33#include <linux/security.h>30#include <linux/security.h>
34#include <linux/pid_namespace.h>31#include <linux/pid_namespace.h>
35 32
36int 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}
63EXPORT_SYMBOL_GPL(set_task_ioprio);
64
65int ioprio_check_cap(int ioprio)33int ioprio_check_cap(int ioprio)
66{34{
67 int class = IOPRIO_PRIO_CLASS(ioprio);35 int class = IOPRIO_PRIO_CLASS(ioprio);
include/linux/iocontext.h+0−2
@@ -116,8 +116,6 @@ struct task_struct; · 115 unmodified lines
116#ifdef CONFIG_BLOCK116#ifdef CONFIG_BLOCK
117void put_io_context(struct io_context *ioc);117void put_io_context(struct io_context *ioc);
118void exit_io_context(struct task_struct *task);118void exit_io_context(struct task_struct *task);
119struct io_context *get_task_io_context(struct task_struct *task,
120 gfp_t gfp_flags, int node);
121int __copy_io(unsigned long clone_flags, struct task_struct *tsk);119int __copy_io(unsigned long clone_flags, struct task_struct *tsk);
122static inline int copy_io(unsigned long clone_flags, struct task_struct *tsk)120static inline int copy_io(unsigned long clone_flags, struct task_struct *tsk)
123{121{

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