[PATCH] io_uring/uring_cmd: add io_uring_cmd_tw_t type alias

Caleb Sander Mateos posted 1 patch 1 month ago
include/linux/io_uring/cmd.h | 13 ++++++++-----
io_uring/uring_cmd.c         |  2 +-
2 files changed, 9 insertions(+), 6 deletions(-)
[PATCH] io_uring/uring_cmd: add io_uring_cmd_tw_t type alias
Posted by Caleb Sander Mateos 1 month ago
Introduce a function pointer type alias io_uring_cmd_tw_t for the
uring_cmd task work callback. This avoids repeating the signature in
several places. Also name both arguments to the callback to clarify what
they represent.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
---
 include/linux/io_uring/cmd.h | 13 ++++++++-----
 io_uring/uring_cmd.c         |  2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h
index 4bd3a7339243..7211157edfe9 100644
--- a/include/linux/io_uring/cmd.h
+++ b/include/linux/io_uring/cmd.h
@@ -9,15 +9,18 @@
 /* only top 8 bits of sqe->uring_cmd_flags for kernel internal use */
 #define IORING_URING_CMD_CANCELABLE	(1U << 30)
 /* io_uring_cmd is being issued again */
 #define IORING_URING_CMD_REISSUE	(1U << 31)
 
+typedef void (*io_uring_cmd_tw_t)(struct io_uring_cmd *cmd,
+				  unsigned issue_flags);
+
 struct io_uring_cmd {
 	struct file	*file;
 	const struct io_uring_sqe *sqe;
 	/* callback to defer completions to task context */
-	void (*task_work_cb)(struct io_uring_cmd *cmd, unsigned);
+	io_uring_cmd_tw_t task_work_cb;
 	u32		cmd_op;
 	u32		flags;
 	u8		pdu[32]; /* available inline for free use */
 };
 
@@ -55,11 +58,11 @@ int io_uring_cmd_import_fixed_vec(struct io_uring_cmd *ioucmd,
  */
 void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, u64 res2,
 			unsigned issue_flags);
 
 void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
-			    void (*task_work_cb)(struct io_uring_cmd *, unsigned),
+			    io_uring_cmd_tw_t task_work_cb,
 			    unsigned flags);
 
 /*
  * Note: the caller should never hard code @issue_flags and only use the
  * mask provided by the core io_uring code.
@@ -104,11 +107,11 @@ static inline int io_uring_cmd_import_fixed_vec(struct io_uring_cmd *ioucmd,
 static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
 		u64 ret2, unsigned issue_flags)
 {
 }
 static inline void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
-			    void (*task_work_cb)(struct io_uring_cmd *, unsigned),
+			    io_uring_tw_t task_work_cb,
 			    unsigned flags)
 {
 }
 static inline void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
 		unsigned int issue_flags)
@@ -141,17 +144,17 @@ static inline void io_uring_cmd_iopoll_done(struct io_uring_cmd *ioucmd,
 	io_uring_cmd_done(ioucmd, ret, res2, 0);
 }
 
 /* users must follow the IOU_F_TWQ_LAZY_WAKE semantics */
 static inline void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd,
-			void (*task_work_cb)(struct io_uring_cmd *, unsigned))
+			io_uring_cmd_tw_t task_work_cb)
 {
 	__io_uring_cmd_do_in_task(ioucmd, task_work_cb, IOU_F_TWQ_LAZY_WAKE);
 }
 
 static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
-			void (*task_work_cb)(struct io_uring_cmd *, unsigned))
+			io_uring_cmd_tw_t task_work_cb)
 {
 	__io_uring_cmd_do_in_task(ioucmd, task_work_cb, 0);
 }
 
 static inline struct task_struct *io_uring_cmd_get_task(struct io_uring_cmd *cmd)
diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
index f5a2642bb407..d76d6d27765c 100644
--- a/io_uring/uring_cmd.c
+++ b/io_uring/uring_cmd.c
@@ -124,11 +124,11 @@ static void io_uring_cmd_work(struct io_kiocb *req, io_tw_token_t tw)
 	/* task_work executor checks the deffered list completion */
 	ioucmd->task_work_cb(ioucmd, flags);
 }
 
 void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
-			void (*task_work_cb)(struct io_uring_cmd *, unsigned),
+			io_uring_cmd_tw_t task_work_cb,
 			unsigned flags)
 {
 	struct io_kiocb *req = cmd_to_io_kiocb(ioucmd);
 
 	if (WARN_ON_ONCE(req->flags & REQ_F_APOLL_MULTISHOT))
-- 
2.45.2
Re: [PATCH] io_uring/uring_cmd: add io_uring_cmd_tw_t type alias
Posted by Klara Modin 3 weeks, 4 days ago
Hi,

On 2025-09-02 10:06:56 -0600, Caleb Sander Mateos wrote:
> Introduce a function pointer type alias io_uring_cmd_tw_t for the
> uring_cmd task work callback. This avoids repeating the signature in
> several places. Also name both arguments to the callback to clarify what
> they represent.
> 
> Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
> ---
>  include/linux/io_uring/cmd.h | 13 ++++++++-----
>  io_uring/uring_cmd.c         |  2 +-
>  2 files changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h
> index 4bd3a7339243..7211157edfe9 100644
> --- a/include/linux/io_uring/cmd.h
> +++ b/include/linux/io_uring/cmd.h
> @@ -9,15 +9,18 @@
>  /* only top 8 bits of sqe->uring_cmd_flags for kernel internal use */
>  #define IORING_URING_CMD_CANCELABLE	(1U << 30)
>  /* io_uring_cmd is being issued again */
>  #define IORING_URING_CMD_REISSUE	(1U << 31)
>  
> +typedef void (*io_uring_cmd_tw_t)(struct io_uring_cmd *cmd,
> +				  unsigned issue_flags);
> +
>  struct io_uring_cmd {
>  	struct file	*file;
>  	const struct io_uring_sqe *sqe;
>  	/* callback to defer completions to task context */
> -	void (*task_work_cb)(struct io_uring_cmd *cmd, unsigned);
> +	io_uring_cmd_tw_t task_work_cb;
>  	u32		cmd_op;
>  	u32		flags;
>  	u8		pdu[32]; /* available inline for free use */
>  };
>  
> @@ -55,11 +58,11 @@ int io_uring_cmd_import_fixed_vec(struct io_uring_cmd *ioucmd,
>   */
>  void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, u64 res2,
>  			unsigned issue_flags);
>  
>  void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
> -			    void (*task_work_cb)(struct io_uring_cmd *, unsigned),
> +			    io_uring_cmd_tw_t task_work_cb,
>  			    unsigned flags);
>  
>  /*
>   * Note: the caller should never hard code @issue_flags and only use the
>   * mask provided by the core io_uring code.
> @@ -104,11 +107,11 @@ static inline int io_uring_cmd_import_fixed_vec(struct io_uring_cmd *ioucmd,
>  static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
>  		u64 ret2, unsigned issue_flags)
>  {
>  }
>  static inline void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,

> -			    void (*task_work_cb)(struct io_uring_cmd *, unsigned),
> +			    io_uring_tw_t task_work_cb,

There seems to have slipped in a typo for the !IO_URING stub here:
s/io_uring_tw_t/io_uring_cmd_tw_t/

>  			    unsigned flags)
>  {
>  }
>  static inline void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
>  		unsigned int issue_flags)

...

Regards,
Klara Modin
Re: [PATCH] io_uring/uring_cmd: add io_uring_cmd_tw_t type alias
Posted by Jens Axboe 3 weeks, 3 days ago
On 9/7/25 6:33 AM, Klara Modin wrote:
>> @@ -104,11 +107,11 @@ static inline int io_uring_cmd_import_fixed_vec(struct io_uring_cmd *ioucmd,
>>  static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
>>  		u64 ret2, unsigned issue_flags)
>>  {
>>  }
>>  static inline void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
> 
>> -			    void (*task_work_cb)(struct io_uring_cmd *, unsigned),
>> +			    io_uring_tw_t task_work_cb,
> 
> There seems to have slipped in a typo for the !IO_URING stub here:
> s/io_uring_tw_t/io_uring_cmd_tw_t/

Indeed, that's my fault. I had to hand apply a few of those patches and
apparently butter fingered that hunk. I've queued up a fixup with a
Reported-by for you, thanks for catching that!

-- 
Jens Axboe
Re: [PATCH] io_uring/uring_cmd: add io_uring_cmd_tw_t type alias
Posted by Jens Axboe 1 month ago
On Tue, 02 Sep 2025 10:06:56 -0600, Caleb Sander Mateos wrote:
> Introduce a function pointer type alias io_uring_cmd_tw_t for the
> uring_cmd task work callback. This avoids repeating the signature in
> several places. Also name both arguments to the callback to clarify what
> they represent.
> 
> 

Applied, thanks!

[1/1] io_uring/uring_cmd: add io_uring_cmd_tw_t type alias
      commit: df3a7762ee24ba6a33d4215244e329ca300f4819

Best regards,
-- 
Jens Axboe
Re: [PATCH] io_uring/uring_cmd: add io_uring_cmd_tw_t type alias
Posted by Keith Busch 1 month ago
On Tue, Sep 02, 2025 at 10:06:56AM -0600, Caleb Sander Mateos wrote:
> Introduce a function pointer type alias io_uring_cmd_tw_t for the
> uring_cmd task work callback. This avoids repeating the signature in
> several places. Also name both arguments to the callback to clarify what
> they represent.

Looks good to me.

Reviewed-by: Keith Busch <kbusch@kernel.org>