diff mbox series

[1/8] block: Fix handling of tasks without ioprio in ioprio_get(2)

Message ID 20220615161616.5055-1-jack@suse.cz (mailing list archive)
State New, archived
Headers show
Series block: Fix IO priority mess | expand

Commit Message

Jan Kara June 15, 2022, 4:16 p.m. UTC
ioprio_get(2) can be asked to return the best IO priority from several
tasks (IOPRIO_WHO_PGRP, IOPRIO_WHO_USER). Currently the call treats
tasks without set IO priority as having priority
IOPRIO_CLASS_BE/IOPRIO_BE_NORM however this does not really reflect the
IO priority the task will get (which depends on task's nice value) and
with the following fix it will not even match returned IO priority for a
single task.

Fix IO priority comparison to treat unset IO priority as the lowest
possible one. This way we will return IOPRIO_CLASS_NONE priority only if
none of the considered tasks has explicitely set IO priority, otherwise
we return the highest set IO priority. This changes userspace visible
behavior but this way the caller really gets back the highest set IO
priority without contaminating the result with
IOPRIO_CLASS_BE/IOPRIO_BE_NORM from tasks which have IO priority unset.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 block/ioprio.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/block/ioprio.c b/block/ioprio.c
index 2fe068fcaad5..62890391fc80 100644
--- a/block/ioprio.c
+++ b/block/ioprio.c
@@ -157,10 +157,9 @@  static int get_task_ioprio(struct task_struct *p)
 int ioprio_best(unsigned short aprio, unsigned short bprio)
 {
 	if (!ioprio_valid(aprio))
-		aprio = IOPRIO_DEFAULT;
+		return bprio;
 	if (!ioprio_valid(bprio))
-		bprio = IOPRIO_DEFAULT;
-
+		return aprio;
 	return min(aprio, bprio);
 }