Skip to content

Commit

Permalink
block: Generalize get_current_ioprio() for any task
Browse files Browse the repository at this point in the history
get_current_ioprio() operates only on current task. We will need the
same functionality for other tasks as well. Generalize
get_current_ioprio() for that and also move the bulk out of the header
file because it is large enough.

Reviewed-by: Damien Le Moal <[email protected]>
Tested-by: Damien Le Moal <[email protected]>
Signed-off-by: Jan Kara <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
jankara authored and axboe committed Jun 27, 2022
1 parent f7eda40 commit 893e5d3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
26 changes: 26 additions & 0 deletions block/ioprio.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,32 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio)
return ret;
}

/*
* If the task has set an I/O priority, use that. Otherwise, return
* the default I/O priority.
*
* Expected to be called for current task or with task_lock() held to keep
* io_context stable.
*/
int __get_task_ioprio(struct task_struct *p)
{
struct io_context *ioc = p->io_context;
int prio;

if (p != current)
lockdep_assert_held(&p->alloc_lock);
if (ioc)
prio = ioc->ioprio;
else
prio = IOPRIO_DEFAULT;

if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(p),
task_nice_ioprio(p));
return prio;
}
EXPORT_SYMBOL_GPL(__get_task_ioprio);

static int get_task_ioprio(struct task_struct *p)
{
int ret;
Expand Down
26 changes: 10 additions & 16 deletions include/linux/ioprio.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,18 @@ static inline int task_nice_ioclass(struct task_struct *task)
return IOPRIO_CLASS_BE;
}

/*
* If the calling process has set an I/O priority, use that. Otherwise, return
* the default I/O priority.
*/
static inline int get_current_ioprio(void)
#ifdef CONFIG_BLOCK
int __get_task_ioprio(struct task_struct *p);
#else
static inline int __get_task_ioprio(struct task_struct *p)
{
struct io_context *ioc = current->io_context;
int prio;

if (ioc)
prio = ioc->ioprio;
else
prio = IOPRIO_DEFAULT;
return IOPRIO_DEFAULT;
}
#endif /* CONFIG_BLOCK */

if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(current),
task_nice_ioprio(current));
return prio;
static inline int get_current_ioprio(void)
{
return __get_task_ioprio(current);
}

/*
Expand Down

0 comments on commit 893e5d3

Please sign in to comment.