Skip to content

Commit

Permalink
libublksrv: replace ublksrv_setup_ring with ublksrv_setup_ring_params
Browse files Browse the repository at this point in the history
Then we can check the returned param and see if some new feature can be
supported.

Signed-off-by: Ming Lei <[email protected]>
  • Loading branch information
ming1 committed Oct 29, 2024
1 parent fa4439c commit 3fc6c38
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
13 changes: 4 additions & 9 deletions include/ublksrv_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,12 @@ static inline int is_target_io(__u64 user_data)
return (user_data & (1ULL << 63)) != 0;
}

/* two helpers for setting up io_uring */
static inline int ublksrv_setup_ring(struct io_uring *r, int depth,
static inline void ublksrv_setup_ring_params(struct io_uring_params *p,
int cq_depth, unsigned flags)
{
struct io_uring_params p;

memset(&p, 0, sizeof(p));
p.flags = flags | IORING_SETUP_CQSIZE;
p.cq_entries = cq_depth;

return io_uring_queue_init_params(depth, r, &p);
memset(p, 0, sizeof(*p));
p->flags = flags | IORING_SETUP_CQSIZE;
p->cq_entries = cq_depth;
}

static inline struct io_uring_sqe *ublksrv_uring_get_sqe(struct io_uring *r,
Expand Down
4 changes: 3 additions & 1 deletion lib/ublksrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ static void ublksrv_calculate_depths(const struct _ublksrv_dev *dev, int
const struct ublksrv_queue *ublksrv_queue_init(const struct ublksrv_dev *tdev,
unsigned short q_id, void *queue_data)
{
struct io_uring_params p;
struct _ublksrv_dev *dev = tdev_to_local(tdev);
struct _ublksrv_queue *q;
const struct ublksrv_ctrl_dev *ctrl_dev = dev->ctrl_dev;
Expand Down Expand Up @@ -595,8 +596,9 @@ const struct ublksrv_queue *ublksrv_queue_init(const struct ublksrv_dev *tdev,
//ublk_assert(io_data_size ^ (unsigned long)q->ios[i].data.private_data);
}

ret = ublksrv_setup_ring(&q->ring, ring_depth, cq_depth,
ublksrv_setup_ring_params(&p, cq_depth,
IORING_SETUP_SQE128 | IORING_SETUP_COOP_TASKRUN);
ret = io_uring_queue_init_params(ring_depth, &q->ring, &p);
if (ret < 0) {
ublk_err("ublk dev %d queue %d setup io_uring failed %d",
q->dev->ctrl_dev->dev_info.dev_id, q->q_id, ret);
Expand Down
4 changes: 3 additions & 1 deletion lib/ublksrv_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ void ublksrv_ctrl_deinit(struct ublksrv_ctrl_dev *dev)

struct ublksrv_ctrl_dev *ublksrv_ctrl_init(struct ublksrv_dev_data *data)
{
struct io_uring_params p;
struct ublksrv_ctrl_dev *dev = (struct ublksrv_ctrl_dev *)calloc(1,
sizeof(*dev));
struct ublksrv_ctrl_dev_info *info = &dev->dev_info;
Expand All @@ -171,7 +172,8 @@ struct ublksrv_ctrl_dev *ublksrv_ctrl_init(struct ublksrv_dev_data *data)
dev->tgt_argv = data->tgt_argv;

/* 32 is enough to send ctrl commands */
ret = ublksrv_setup_ring(&dev->ring, 32, 32, IORING_SETUP_SQE128);
ublksrv_setup_ring_params(&p, 32, IORING_SETUP_SQE128);
ret = io_uring_queue_init_params(32, &dev->ring, &p);
if (ret < 0) {
fprintf(stderr, "queue_init: %s\n", strerror(-ret));
free(dev);
Expand Down

0 comments on commit 3fc6c38

Please sign in to comment.