summaryrefslogtreecommitdiff
path: root/block/ioprio.c
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2022-06-23 10:48:28 +0300
committerJens Axboe <axboe@kernel.dk>2022-06-27 15:29:12 +0300
commit893e5d32d5832674bcf6465f27958e883b72b346 (patch)
tree4b20c6a89835a6ffca1f5af19703a90622b3ec46 /block/ioprio.c
parentf7eda402878b12bc0884c5bc1192a9e76ad121fb (diff)
downloadlinux-893e5d32d5832674bcf6465f27958e883b72b346.tar.xz
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>
Diffstat (limited to 'block/ioprio.c')
-rw-r--r--block/ioprio.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/block/ioprio.c b/block/ioprio.c
index 2a34cbca18ae..c4e3476155a1 100644
--- a/block/ioprio.c
+++ b/block/ioprio.c
@@ -138,6 +138,32 @@ out:
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;