ublk: specify io_cmd_buf pointer type
Subsystems (3)
cover ublk: specify io_cmd_buf pointer type
io_cmd_buf points to an array of ublksrv_io_desc structs but its type is char *. Indexing the array requires an explicit multiplication and cast. The compiler also can't check the pointer types.
Change io_cmd_buf's type to struct ublksrv_io_desc * so it can be indexed directly and the compiler can type-check the code.
Make the same change to the ublk selftests.
Caleb Sander Mateos (2):
ublk: specify io_cmd_buf pointer type
selftests: ublk: specify io_cmd_buf pointer type
drivers/block/ublk_drv.c | 8 ++++---- tools/testing/selftests/ublk/kublk.c | 2 +- tools/testing/selftests/ublk/kublk.h | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/2 ublk: specify io_cmd_buf pointer type
io_cmd_buf points to an array of ublksrv_io_desc structs but its type is char *. Indexing the array requires an explicit multiplication and cast. The compiler also can't check the pointer types.
Change io_cmd_buf's type to struct ublksrv_io_desc * so it can be indexed directly and the compiler can type-check the code.
--- drivers/block/ublk_drv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/block/ublk_drv.c +4 -4
@@ -153,11 +153,11 @@ struct ublk_queue {int q_id;int q_depth;unsigned long flags;struct task_struct *ubq_daemon; -char *io_cmd_buf; +struct ublksrv_io_desc *io_cmd_buf;bool force_abort;bool timeout;bool canceling;bool fail_io;/* copy of dev->state == UBLK_S_DEV_FAIL_IO */
@@ -701,15 +701,15 @@ static inline bool ublk_rq_has_data(const struct request *rq) }static inline struct ublksrv_io_desc *ublk_get_iod (struct ublk_queue *ubq,int tag) { -return (struct ublksrv_io_desc *) - &(ubq->io_cmd_buf[tag *sizeof (struct ublksrv_io_desc )]); +return &ubq->io_cmd_buf[tag]; } -static inline char *ublk_queue_cmd_buf (struct ublk_device *ub,int q_id) +static inline struct ublksrv_io_desc * +ublk_queue_cmd_buf (struct ublk_device *ub,int q_id) {return ublk_get_queue (ub, q_id)->io_cmd_buf; }static inline int __ublk_queue_cmd_buf_size (int depth)
Signature · 1 line
2.45.2
PATCH 2/2 selftests: ublk: specify io_cmd_buf pointer type
In reply to Caleb Sander MateosMatching the ublk driver, change the type of io_cmd_buf from char * to struct ublksrv_io_desc *.
--- tools/testing/selftests/ublk/kublk.c | 2 +- tools/testing/selftests/ublk/kublk.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/ublk/kublk.c +1 -1
@@ -320,11 +320,11 @@ static int ublk_queue_init(struct ublk_queue *q) q->state |=UBLKSRV_ZC ; } cmd_buf_size =ublk_queue_cmd_buf_sz (q); off =UBLKSRV_CMD_BUF_OFFSET + q->q_id *ublk_queue_max_cmd_buf_sz (); - q->io_cmd_buf = (char *)mmap (0 , cmd_buf_size,PROT_READ , + q->io_cmd_buf =mmap (0 , cmd_buf_size,PROT_READ ,MAP_SHARED |MAP_POPULATE , dev->fds[0 ], off);if (q->io_cmd_buf ==MAP_FAILED ) {ublk_err ("ublk dev %d queue %d map io_cmd_buf failed %m\n" , q->dev->dev_info.dev_id, q->q_id); goto fail;
tools/testing/selftests/ublk/kublk.h +2 -2
@@ -126,11 +126,11 @@ struct ublk_queue {int q_depth;unsigned int cmd_inflight;unsigned int io_inflight;struct ublk_dev *dev;const struct ublk_tgt_ops *tgt_ops; -char *io_cmd_buf; +struct ublksrv_io_desc *io_cmd_buf;struct io_uring ring;struct ublk_io ios[UBLK_QUEUE_DEPTH ];#define UBLKSRV_QUEUE_STOPPING (1U << 0)#define UBLKSRV_QUEUE_IDLE (1U << 1)#define UBLKSRV_NO_BUF (1U << 2)
@@ -300,11 +300,11 @@ static inline void ublk_mark_io_done(struct ublk_io *io, int res) io->result = res; }static inline const struct ublksrv_io_desc *ublk_get_iod (const struct ublk_queue *q,int tag) { -return (struct ublksrv_io_desc *)&(q->io_cmd_buf[tag *sizeof (struct ublksrv_io_desc )]); +return &q->io_cmd_buf[tag]; }static inline void ublk_set_sqe_cmd_op (struct io_uring_sqe *sqe,__u32 cmd_op) {__u32 *addr = (__u32 *)&sqe->off;
Signature · 1 line
2.45.2
Jens Axboe
maintainerQuoted 8 lines · Caleb Sander Mateos
io_cmd_bufpoints to an array ofublksrv_io_descstructs but its type is char *. Indexing the array requires an explicit multiplication and cast. The compiler also can't check the pointer types.Change io_cmd_buf's type to struct
ublksrv_io_desc* so it can be indexed directly and the compiler can type-check the code.Make the same change to the ublk selftests.
Looks good to me, nice cleanup, more readable now.
Signature · 1 line
Jens Axboe
Quoted 9 lines · Caleb Sander Mateos
io_cmd_bufpoints to an array ofublksrv_io_descstructs but its type is char *. Indexing the array requires an explicit multiplication and cast. The compiler also can't check the pointer types.Change io_cmd_buf's type to struct
ublksrv_io_desc* so it can be indexed directly and the compiler can type-check the code.Make the same change to the ublk selftests.
Quoted 9 lines
Caleb Sander Mateos (2):
ublk: specifyio_cmd_bufpointer type
selftests: ublk: specifyio_cmd_bufpointer typedrivers/block/ublk_drv.c | 8 ++++---- tools/testing/selftests/ublk/kublk.c | 2 +- tools/testing/selftests/ublk/kublk.h | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-)
For selftests changes:
thanks,
-- Shuah
Quoted 9 lines · Caleb Sander Mateos
io_cmd_bufpoints to an array ofublksrv_io_descstructs but its type is char *. Indexing the array requires an explicit multiplication and cast. The compiler also can't check the pointer types.Change io_cmd_buf's type to struct
ublksrv_io_desc* so it can be indexed directly and the compiler can type-check the code.Make the same change to the ublk selftests.
Quoted 8 lines
Caleb Sander Mateos (2):
ublk: specifyio_cmd_bufpointer type
selftests: ublk: specifyio_cmd_bufpointer typedrivers/block/ublk_drv.c | 8 ++++---- tools/testing/selftests/ublk/kublk.c | 2 +- tools/testing/selftests/ublk/kublk.h | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-)
Thanks,
Ming
Quoted 8 lines · Caleb Sander Mateos
io_cmd_bufpoints to an array ofublksrv_io_descstructs but its type is char *. Indexing the array requires an explicit multiplication and cast. The compiler also can't check the pointer types.Change io_cmd_buf's type to struct
ublksrv_io_desc* so it can be indexed directly and the compiler can type-check the code.[...]
Applied, thanks!
[1/2] ublk: specify io_cmd_buf pointer type
commit: 9a45714fc51321ea8f5e5567f70e06753a848f62
[2/2] selftests: ublk: specify io_cmd_buf pointer type
commit: 25aaa81371e7db34ddb42c69ed4f6c5bc8de2afaBest regards,
Signature · 1 line
Jens Axboe