Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: Generalize get_current_ioprio() for any task

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 <damien.lemoal@opensource.wdc.com>
Tested-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220623074840.5960-3-jack@suse.cz
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Jan Kara and committed by
Jens Axboe
893e5d32 f7eda402

+36 -16
+26
block/ioprio.c
··· 138 138 return ret; 139 139 } 140 140 141 + /* 142 + * If the task has set an I/O priority, use that. Otherwise, return 143 + * the default I/O priority. 144 + * 145 + * Expected to be called for current task or with task_lock() held to keep 146 + * io_context stable. 147 + */ 148 + int __get_task_ioprio(struct task_struct *p) 149 + { 150 + struct io_context *ioc = p->io_context; 151 + int prio; 152 + 153 + if (p != current) 154 + lockdep_assert_held(&p->alloc_lock); 155 + if (ioc) 156 + prio = ioc->ioprio; 157 + else 158 + prio = IOPRIO_DEFAULT; 159 + 160 + if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE) 161 + prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(p), 162 + task_nice_ioprio(p)); 163 + return prio; 164 + } 165 + EXPORT_SYMBOL_GPL(__get_task_ioprio); 166 + 141 167 static int get_task_ioprio(struct task_struct *p) 142 168 { 143 169 int ret;
+10 -16
include/linux/ioprio.h
··· 46 46 return IOPRIO_CLASS_BE; 47 47 } 48 48 49 - /* 50 - * If the calling process has set an I/O priority, use that. Otherwise, return 51 - * the default I/O priority. 52 - */ 49 + #ifdef CONFIG_BLOCK 50 + int __get_task_ioprio(struct task_struct *p); 51 + #else 52 + static inline int __get_task_ioprio(struct task_struct *p) 53 + { 54 + return IOPRIO_DEFAULT; 55 + } 56 + #endif /* CONFIG_BLOCK */ 57 + 53 58 static inline int get_current_ioprio(void) 54 59 { 55 - struct io_context *ioc = current->io_context; 56 - int prio; 57 - 58 - if (ioc) 59 - prio = ioc->ioprio; 60 - else 61 - prio = IOPRIO_DEFAULT; 62 - 63 - if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE) 64 - prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(current), 65 - task_nice_ioprio(current)); 66 - return prio; 60 + return __get_task_ioprio(current); 67 61 } 68 62 69 63 /*