@@ -8,6 +8,16 @@
#include <uapi/linux/ioprio.h>
+/*
+ * Check that a priority value has a valid class.
+ */
+static inline bool ioprio_valid(unsigned short ioprio)
+{
+ unsigned short class = IOPRIO_PRIO_CLASS(ioprio);
+
+ return class > IOPRIO_CLASS_NONE && class < IOPRIO_CLASS_MAX;
+}
+
/*
* if process has set io priority explicitly, use that. if not, convert
* the cpu scheduler nice value to an io priority
@@ -25,10 +35,9 @@ static inline int task_nice_ioclass(struct task_struct *task)
{
if (task->policy == SCHED_IDLE)
return IOPRIO_CLASS_IDLE;
- else if (task_is_realtime(task))
+ if (task_is_realtime(task))
return IOPRIO_CLASS_RT;
- else
- return IOPRIO_CLASS_BE;
+ return IOPRIO_CLASS_BE;
}
/*
@@ -5,12 +5,15 @@
/*
* Gives us 8 prio classes with 13-bits of data for each class
*/
-#define IOPRIO_CLASS_SHIFT (13)
+#define IOPRIO_CLASS_SHIFT 13
+#define IOPRIO_CLASS_MASK 0x07
#define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1)
-#define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT)
-#define IOPRIO_PRIO_DATA(mask) ((mask) & IOPRIO_PRIO_MASK)
-#define IOPRIO_PRIO_VALUE(class, data) (((class) << IOPRIO_CLASS_SHIFT) | data)
+#define IOPRIO_PRIO_CLASS(ioprio) \
+ (((ioprio) >> IOPRIO_CLASS_SHIFT) & IOPRIO_CLASS_MASK)
+#define IOPRIO_PRIO_DATA(ioprio) ((ioprio) & IOPRIO_PRIO_MASK)
+#define IOPRIO_PRIO_VALUE(class, data) \
+ (((class) << IOPRIO_CLASS_SHIFT) | ((data) & IOPRIO_PRIO_MASK))
/*
* These are the io priority groups as implemented by CFQ. RT is the realtime
@@ -23,14 +26,14 @@ enum {
IOPRIO_CLASS_RT,
IOPRIO_CLASS_BE,
IOPRIO_CLASS_IDLE,
-};
-#define ioprio_valid(mask) (IOPRIO_PRIO_CLASS((mask)) != IOPRIO_CLASS_NONE)
+ IOPRIO_CLASS_MAX,
+};
/*
* 8 best effort priority levels are supported
*/
-#define IOPRIO_BE_NR (8)
+#define IOPRIO_BE_NR 8
enum {
IOPRIO_WHO_PROCESS = 1,
@@ -41,6 +44,6 @@ enum {
/*
* Fallback BE priority
*/
-#define IOPRIO_NORM (4)
+#define IOPRIO_NORM 4
#endif /* _UAPI_LINUX_IOPRIO_H */