diff mbox series

[v4,3/6] block: change ioprio_valid() to an inline function

Message ID 20210811033702.368488-4-damien.lemoal@wdc.com (mailing list archive)
State New, archived
Headers show
Series IO priority fixes and improvements | expand

Commit Message

Damien Le Moal Aug. 11, 2021, 3:36 a.m. UTC
Change the ioprio_valid() macro in include/usapi/linux/ioprio.h to an
inline function declared on the kernel side in include/linux/ioprio.h.
Also improve checks on the class value by checking the upper bound
value.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 include/linux/ioprio.h      | 10 ++++++++++
 include/uapi/linux/ioprio.h |  2 --
 2 files changed, 10 insertions(+), 2 deletions(-)

Comments

Johannes Thumshirn Aug. 11, 2021, 7:56 a.m. UTC | #1
On 11/08/2021 05:37, Damien Le Moal wrote:
> Change the ioprio_valid() macro in include/usapi/linux/ioprio.h to an                                        uapi ~^

> inline function declared on the kernel side in include/linux/ioprio.h.
> Also improve checks on the class value by checking the upper bound
> value.

But I think it needs to stay in include/uapi/linux/ioprio.h as it's there
since the 2.6.x days (I've checked back to v2.6.39.4) so the chance of
user-space using it is quite high.
Damien Le Moal Aug. 11, 2021, 8:51 a.m. UTC | #2
On 2021/08/11 16:56, Johannes Thumshirn wrote:
> On 11/08/2021 05:37, Damien Le Moal wrote:
>> Change the ioprio_valid() macro in include/usapi/linux/ioprio.h to an                                        uapi ~^
> 
>> inline function declared on the kernel side in include/linux/ioprio.h.
>> Also improve checks on the class value by checking the upper bound
>> value.
> 
> But I think it needs to stay in include/uapi/linux/ioprio.h as it's there
> since the 2.6.x days (I've checked back to v2.6.39.4) so the chance of
> user-space using it is quite high.

include/uapi/linux/ioprio.h is being introduced with kernel 5.15. This user
header did not exist now and in previous kernels. include/linux/ioprio.h has
been around for a while though, but that is a kernel header, not an application
header.
Johannes Thumshirn Aug. 11, 2021, 9:14 a.m. UTC | #3
On 11/08/2021 10:51, Damien Le Moal wrote:
> On 2021/08/11 16:56, Johannes Thumshirn wrote:
>> On 11/08/2021 05:37, Damien Le Moal wrote:
>>> Change the ioprio_valid() macro in include/usapi/linux/ioprio.h to an                                        uapi ~^
>>
>>> inline function declared on the kernel side in include/linux/ioprio.h.
>>> Also improve checks on the class value by checking the upper bound
>>> value.
>>
>> But I think it needs to stay in include/uapi/linux/ioprio.h as it's there
>> since the 2.6.x days (I've checked back to v2.6.39.4) so the chance of
>> user-space using it is quite high.
> 
> include/uapi/linux/ioprio.h is being introduced with kernel 5.15. This user
> header did not exist now and in previous kernels. include/linux/ioprio.h has
> been around for a while though, but that is a kernel header, not an application
> header.
> 
> 

Ah ok this was the now or never one, I thought it was about one of the constants.
Sorry for the noise.
diff mbox series

Patch

diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h
index ef9ad4fb245f..2ee3373684b1 100644
--- a/include/linux/ioprio.h
+++ b/include/linux/ioprio.h
@@ -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_IDLE;
+}
+
 /*
  * if process has set io priority explicitly, use that. if not, convert
  * the cpu scheduler nice value to an io priority
diff --git a/include/uapi/linux/ioprio.h b/include/uapi/linux/ioprio.h
index 6b735854aebd..5064e230374c 100644
--- a/include/uapi/linux/ioprio.h
+++ b/include/uapi/linux/ioprio.h
@@ -27,8 +27,6 @@  enum {
 	IOPRIO_CLASS_IDLE,
 };
 
-#define ioprio_valid(mask)	(IOPRIO_PRIO_CLASS((mask)) != IOPRIO_CLASS_NONE)
-
 /*
  * 8 best effort priority levels are supported
  */