Commit 4bf9cbf3 authored by Ming Lei's avatar Ming Lei Committed by Jens Axboe

ublk_drv: cleanup ublksrv_ctrl_dev_info

Remove all block device related info from ublksrv_ctrl_dev_info,
meantime reduce its size into 64 bytes because:

1) ublksrv_ctrl_dev_info becomes cleaner without including any
block related info

2) generic set/get parameter command can be used to set block
related setting easily and cleanly

3) generic set/get parameter command can be used for extending
ublk without needing more info in ublksrv_ctrl_dev_info
Signed-off-by: default avatarMing Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20220730092750.1118167-5-ming.lei@redhat.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 0aa73170
...@@ -122,7 +122,6 @@ struct ublk_device { ...@@ -122,7 +122,6 @@ struct ublk_device {
char *__queues; char *__queues;
unsigned short queue_size; unsigned short queue_size;
unsigned short bs_shift;
struct ublksrv_ctrl_dev_info dev_info; struct ublksrv_ctrl_dev_info dev_info;
struct blk_mq_tag_set tag_set; struct blk_mq_tag_set tag_set;
...@@ -223,8 +222,7 @@ static int ublk_validate_params(const struct ublk_device *ub) ...@@ -223,8 +222,7 @@ static int ublk_validate_params(const struct ublk_device *ub)
if (p->logical_bs_shift > p->physical_bs_shift) if (p->logical_bs_shift > p->physical_bs_shift)
return -EINVAL; return -EINVAL;
if (p->max_sectors > (ub->dev_info.rq_max_blocks << if (p->max_sectors > (ub->dev_info.max_io_buf_bytes >> 9))
(ub->bs_shift - 9)))
return -EINVAL; return -EINVAL;
} else } else
return -EINVAL; return -EINVAL;
...@@ -1185,13 +1183,13 @@ static void ublk_stop_work_fn(struct work_struct *work) ...@@ -1185,13 +1183,13 @@ static void ublk_stop_work_fn(struct work_struct *work)
ublk_stop_dev(ub); ublk_stop_dev(ub);
} }
/* align maximum I/O size to PAGE_SIZE */ /* align max io buffer size with PAGE_SIZE */
static void ublk_align_max_io_size(struct ublk_device *ub) static void ublk_align_max_io_size(struct ublk_device *ub)
{ {
unsigned int max_rq_bytes = ub->dev_info.rq_max_blocks << ub->bs_shift; unsigned int max_io_bytes = ub->dev_info.max_io_buf_bytes;
ub->dev_info.rq_max_blocks = ub->dev_info.max_io_buf_bytes =
round_down(max_rq_bytes, PAGE_SIZE) >> ub->bs_shift; round_down(max_io_bytes, PAGE_SIZE);
} }
static int ublk_add_tag_set(struct ublk_device *ub) static int ublk_add_tag_set(struct ublk_device *ub)
...@@ -1348,9 +1346,8 @@ static inline void ublk_dump_dev_info(struct ublksrv_ctrl_dev_info *info) ...@@ -1348,9 +1346,8 @@ static inline void ublk_dump_dev_info(struct ublksrv_ctrl_dev_info *info)
{ {
pr_devel("%s: dev id %d flags %llx\n", __func__, pr_devel("%s: dev id %d flags %llx\n", __func__,
info->dev_id, info->flags); info->dev_id, info->flags);
pr_devel("\t nr_hw_queues %d queue_depth %d block size %d dev_capacity %lld\n", pr_devel("\t nr_hw_queues %d queue_depth %d\n",
info->nr_hw_queues, info->queue_depth, info->nr_hw_queues, info->queue_depth);
info->block_size, info->dev_blocks);
} }
static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd) static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd)
...@@ -1410,7 +1407,6 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd) ...@@ -1410,7 +1407,6 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd)
/* We are not ready to support zero copy */ /* We are not ready to support zero copy */
ub->dev_info.flags &= ~UBLK_F_SUPPORT_ZERO_COPY; ub->dev_info.flags &= ~UBLK_F_SUPPORT_ZERO_COPY;
ub->bs_shift = ilog2(ub->dev_info.block_size);
ub->dev_info.nr_hw_queues = min_t(unsigned int, ub->dev_info.nr_hw_queues = min_t(unsigned int,
ub->dev_info.nr_hw_queues, nr_cpu_ids); ub->dev_info.nr_hw_queues, nr_cpu_ids);
ublk_align_max_io_size(ub); ublk_align_max_io_size(ub);
......
...@@ -80,22 +80,23 @@ struct ublksrv_ctrl_cmd { ...@@ -80,22 +80,23 @@ struct ublksrv_ctrl_cmd {
struct ublksrv_ctrl_dev_info { struct ublksrv_ctrl_dev_info {
__u16 nr_hw_queues; __u16 nr_hw_queues;
__u16 queue_depth; __u16 queue_depth;
__u16 block_size;
__u16 state; __u16 state;
__u16 pad0;
__u32 rq_max_blocks; __u32 max_io_buf_bytes;
__u32 dev_id; __u32 dev_id;
__u64 dev_blocks;
__s32 ublksrv_pid; __s32 ublksrv_pid;
__s32 reserved0; __u32 pad1;
__u64 flags; __u64 flags;
__u64 flags_reserved;
/* For ublksrv internal use, invisible to ublk driver */ /* For ublksrv internal use, invisible to ublk driver */
__u64 ublksrv_flags; __u64 ublksrv_flags;
__u64 reserved1[9];
__u64 reserved0;
__u64 reserved1;
__u64 reserved2;
}; };
#define UBLK_IO_OP_READ 0 #define UBLK_IO_OP_READ 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment