| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include <sys/ioprio.h> /* IWYU pragma: export */ |
| 5 |
|
| 6 |
#include "shared-forward.h" |
| 7 |
|
| 8 |
static inline int ioprio_prio_class(int value) { |
| 9 |
return IOPRIO_PRIO_CLASS(value); |
| 10 |
} |
| 11 |
|
| 12 |
static inline int ioprio_prio_data(int value) { |
| 13 |
return IOPRIO_PRIO_DATA(value); |
| 14 |
} |
| 15 |
|
| 16 |
static inline int ioprio_prio_value(int class, int data) { |
| 17 |
return IOPRIO_PRIO_VALUE_HINT(class, IOPRIO_PRIO_LEVEL(data), IOPRIO_PRIO_HINT(data)); |
| 18 |
} |
| 19 |
|
| 20 |
DECLARE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int); |
| 21 |
|
| 22 |
static inline bool ioprio_class_is_valid(int i) { |
| 23 |
return IN_SET(i, IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT, IOPRIO_CLASS_BE, IOPRIO_CLASS_IDLE); |
| 24 |
} |
| 25 |
|
| 26 |
static inline bool ioprio_priority_is_valid(int i) { |
| 27 |
return i >= 0 && i < IOPRIO_NR_LEVELS; |
| 28 |
} |
| 29 |
|
| 30 |
int ioprio_parse_priority(const char *s, int *ret); |
| 31 |
|
| 32 |
/* IOPRIO_CLASS_NONE with any prio value is another way to say IOPRIO_CLASS_BE with level 4. Encode that in a |
| 33 |
* proper macro. */ |
| 34 |
#define IOPRIO_DEFAULT_CLASS_AND_PRIO ioprio_prio_value(IOPRIO_CLASS_BE, 4) |
| 35 |
|
| 36 |
static inline int ioprio_normalize(int v) { |
| 37 |
/* Converts IOPRIO_CLASS_NONE to what it actually means */ |
| 38 |
return ioprio_prio_class(v) == IOPRIO_CLASS_NONE ? IOPRIO_DEFAULT_CLASS_AND_PRIO : v; |
| 39 |
} |