Skip to content

Commit

Permalink
libublksrv: ABI change: allow target/backend to request extra io slot…
Browse files Browse the repository at this point in the history
… allocation

target/backend may need extra io slot for handling specific io, such as
meta background io.

And this slots will be managed by target/backend code, and libublksrv
won't touch them at all.

This change breaks ABI of libublksrv, so please update libublksrv.

It is planned to stabilize libublksrv ABI in v1.0 release, and hope it
can be done soon.

Signed-off-by: Ming Lei <[email protected]>
  • Loading branch information
ming1 committed Sep 11, 2022
1 parent cca1033 commit 29de3e4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion demo_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static void *demo_event_io_handler_fn(void *data)
q_id, gettid());
pthread_mutex_unlock(&jbuf_lock);

q = ublksrv_queue_init(dev, q_id, info);
q = ublksrv_queue_init(dev, q_id, 0, info);
if (!q) {
fprintf(stderr, "ublk dev %d queue %d init queue failed\n",
dev->ctrl_dev->dev_info.dev_id, q_id);
Expand Down
2 changes: 1 addition & 1 deletion demo_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void *demo_null_io_handler_fn(void *data)
ublksrv_json_write_queue_info(dev->ctrl_dev, jbuf, sizeof jbuf,
q_id, gettid());
pthread_mutex_unlock(&jbuf_lock);
q = ublksrv_queue_init(dev, q_id, NULL);
q = ublksrv_queue_init(dev, q_id, 0, NULL);
if (!q) {
fprintf(stderr, "ublk dev %d queue %d init queue failed\n",
dev->ctrl_dev->dev_info.dev_id, q_id);
Expand Down
5 changes: 4 additions & 1 deletion include/ublksrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ struct ublksrv_tgt_type {
int type;
unsigned ublk_flags; //flags required for ublk driver
unsigned ublksrv_flags; //flags required for ublksrv
int extra_ios; //extra io slots allocated for handling
//target specific IOs, such as meta io
const char *name;

/*
Expand Down Expand Up @@ -372,7 +374,8 @@ static inline void *ublksrv_queue_get_data(const struct ublksrv_queue *q)
}

extern struct ublksrv_queue *ublksrv_queue_init(struct ublksrv_dev *dev,
unsigned short q_id, void *queue_data);
unsigned short q_id, unsigned short nr_extra_ios,
void *queue_data);
extern void ublksrv_queue_deinit(struct ublksrv_queue *q);
extern int ublksrv_queue_handled_event(struct ublksrv_queue *q);
extern int ublksrv_queue_send_event(struct ublksrv_queue *q);
Expand Down
19 changes: 16 additions & 3 deletions lib/ublksrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,17 @@ static int ublksrv_setup_eventfd(struct ublksrv_queue *q)
return 0;
}

/*
* target/backend may need some extra io slots for handling something
* like meta data flushing in background, so allow target to pass
* this info via 'nr_extra_ios' which can't be > queue_depth.
*
* And it is target code's responsibility for managing these extra
* slots, and libublksrv won't touch these slots at all.
*/
struct ublksrv_queue *ublksrv_queue_init(struct ublksrv_dev *dev,
unsigned short q_id, void *queue_data)
unsigned short q_id, unsigned short nr_extra_ios,
void *queue_data)
{
struct ublksrv_queue *q;
const struct ublksrv_ctrl_dev *ctrl_dev = dev->ctrl_dev;
Expand All @@ -518,9 +527,13 @@ struct ublksrv_queue *ublksrv_queue_init(struct ublksrv_dev *dev,
int cmd_buf_size, io_buf_size;
unsigned long off;
int ring_depth = depth + dev->tgt.tgt_ring_depth;
int nr_ios = depth + nr_extra_ios;

if (nr_extra_ios > depth)
return NULL;

q = (struct ublksrv_queue *)malloc(sizeof(struct ublksrv_queue) + sizeof(struct ublk_io) *
ctrl_dev->dev_info.queue_depth);
q = (struct ublksrv_queue *)malloc(sizeof(struct ublksrv_queue) +
sizeof(struct ublk_io) * nr_ios);
dev->__queues[q_id] = q;

q->dev = dev;
Expand Down
2 changes: 1 addition & 1 deletion ublksrv_tgt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static void *ublksrv_io_handler_fn(void *data)
ublksrv_tgt_store_dev_data(dev, buf);
pthread_mutex_unlock(&jbuf_lock);

q = ublksrv_queue_init(dev, q_id, NULL);
q = ublksrv_queue_init(dev, q_id, dev->tgt.ops->extra_ios, NULL);
if (!q) {
syslog(LOG_INFO, "ublk dev %d queue %d init queue failed",
dev->ctrl_dev->dev_info.dev_id, q_id);
Expand Down

0 comments on commit 29de3e4

Please sign in to comment.