Skip to content

Commit

Permalink
wip: zone append
Browse files Browse the repository at this point in the history
  • Loading branch information
metaspace committed Jun 28, 2023
1 parent a615b13 commit 7de0d90
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 84 deletions.
3 changes: 2 additions & 1 deletion include/ublk_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ struct ublk_param_devt {
struct ublk_param_zoned {
__u32 max_open_zones;
__u32 max_active_zones;
__u8 reserved[24];
__u32 max_zone_append_sectors;
__u8 reserved[20];
};

struct ublk_params {
Expand Down
16 changes: 16 additions & 0 deletions include/ublksrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <stdbool.h>
#include <assert.h>
#include <sys/queue.h>

#include "liburing.h"

Expand Down Expand Up @@ -88,6 +89,13 @@ struct ublk_io_data {
#define UBLKSRV_QUEUE_IOCTL_OP (1U << 2)
#define UBLKSRV_USER_COPY (1U << 3)

struct iod_queue_entry {
struct ublk_io_tgt *io;
STAILQ_ENTRY(iod_queue_entry) entry;
};

STAILQ_HEAD(iod_queue_head, iod_queue_entry);

/**
* ublksrv_queue is 1:1 mapping with ublk driver's blk-mq queue, and
* has same queue depth with ublk driver's blk-mq queue.
Expand All @@ -105,6 +113,8 @@ struct ublksrv_queue {
/** which device this queue belongs to */
const struct ublksrv_dev *dev;

struct iod_queue_head waiting;

/** queue's private data, passed from ublksrv_queue_init() */
void *private_data;
};
Expand Down Expand Up @@ -247,6 +257,8 @@ struct ublksrv_tgt_type {
void (*handle_io_background)(const struct ublksrv_queue *, int
nr_queued_io);


bool (*handle_io_queued)(struct ublksrv_queue *q);
/**
* show target specific command line for adding new device
*
Expand Down Expand Up @@ -891,8 +903,12 @@ extern int ublksrv_process_io(const struct ublksrv_queue *q);
* @param res io result
*/
extern int ublksrv_complete_io(const struct ublksrv_queue *q, unsigned tag, int res);

extern int ublksrv_complete_io_alba(const struct ublksrv_queue *tq, unsigned tag,
int res, __u64 alba);
/** @} */ // end of ublksrv_queue group


#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/ublksrv_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <sys/eventfd.h>
#include <sys/epoll.h>
#include <sys/poll.h>
#include <sys/queue.h>

#include "ublk_cmd.h"
#include "ublksrv_utils.h"
Expand Down Expand Up @@ -86,6 +87,7 @@ struct _ublksrv_queue {

struct io_uring *ring_ptr;
struct _ublksrv_dev *dev;
struct iod_queue_head waiting;
void *private_data;
/*************************************************/

Expand Down
2 changes: 2 additions & 0 deletions include/ublksrv_tgt.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ struct ublk_io_tgt {
co_handle_type co;
const struct io_uring_cqe *tgt_io_cqe;
int queued_tgt_io; /* obsolete */
int suspend_reason;
__u64 zone_append_alba;
};

static inline struct ublk_io_tgt *__ublk_get_io_tgt_data(const struct ublk_io_data *io)
Expand Down
31 changes: 27 additions & 4 deletions lib/ublksrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ static void ublksrv_tgt_deinit(struct _ublksrv_dev *dev)
}

static inline int ublksrv_queue_io_cmd(struct _ublksrv_queue *q,
struct ublk_io *io, unsigned tag)
struct ublk_io *io, unsigned tag,
char use_alba,
__u64 alba)
{
struct ublksrv_io_cmd *cmd;
struct io_uring_sqe *sqe;
Expand Down Expand Up @@ -170,8 +172,11 @@ static inline int ublksrv_queue_io_cmd(struct _ublksrv_queue *q,
cmd->tag = tag;
if (!(q->state & UBLKSRV_USER_COPY))
cmd->addr = (__u64)io->buf_addr;
else if (use_alba)
cmd->addr = alba;
else
cmd->addr = 0;

cmd->q_id = q->q_id;

user_data = build_user_data(tag, _IOC_NR(cmd_op), 0, 0);
Expand All @@ -195,7 +200,19 @@ int ublksrv_complete_io(const struct ublksrv_queue *tq, unsigned tag, int res)

ublksrv_mark_io_done(io, res);

return ublksrv_queue_io_cmd(q, io, tag);
return ublksrv_queue_io_cmd(q, io, tag, 0, 0);
}

int ublksrv_complete_io_alba(const struct ublksrv_queue *tq, unsigned tag,
int res, __u64 alba)
{
struct _ublksrv_queue *q = tq_to_local(tq);

struct ublk_io *io = &q->ios[tag];

ublksrv_mark_io_done(io, res);

return ublksrv_queue_io_cmd(q, io, tag, 1, alba);
}

/*
Expand Down Expand Up @@ -285,7 +302,7 @@ static void ublksrv_submit_fetch_commands(struct _ublksrv_queue *q)
int i = 0;

for (i = 0; i < q->q_depth; i++)
ublksrv_queue_io_cmd(q, &q->ios[i], i);
ublksrv_queue_io_cmd(q, &q->ios[i], i, 0, 0);

__ublksrv_queue_event(q);
}
Expand Down Expand Up @@ -516,6 +533,7 @@ const struct ublksrv_queue *ublksrv_queue_init(const struct ublksrv_dev *tdev,
sizeof(struct ublk_io) * nr_ios);
dev->__queues[q_id] = q;

STAILQ_INIT(&q->waiting);
q->tgt_ops = dev->tgt.ops; //cache ops for fast path
q->dev = dev;
if (ctrl_dev->dev_info.flags & UBLK_F_CMD_IOCTL_ENCODE)
Expand Down Expand Up @@ -804,7 +822,7 @@ static void ublksrv_handle_cqe(struct io_uring *r,
q->tgt_ops->handle_io_async(local_to_tq(q), &io->data);
} else if (cqe->res == UBLK_IO_RES_NEED_GET_DATA) {
io->flags |= UBLKSRV_NEED_GET_DATA | UBLKSRV_IO_FREE;
ublksrv_queue_io_cmd(q, io, tag);
ublksrv_queue_io_cmd(q, io, tag, 0, 0);
} else {
/*
* COMMIT_REQ will be completed immediately since no fetching
Expand Down Expand Up @@ -910,12 +928,17 @@ int ublksrv_process_io(const struct ublksrv_queue *tq)
if (ublksrv_queue_is_done(q))
return -ENODEV;

again:
ret = io_uring_submit_and_wait_timeout(&q->ring, &cqe, 1, tsp, NULL);

ublksrv_reset_aio_batch(q);
reapped = ublksrv_reap_events_uring(&q->ring);
ublksrv_submit_aio_batch(q);

if (q->tgt_ops->handle_io_queued)
if (!q->tgt_ops->handle_io_queued(local_to_tq(q)))
goto again;

if (q->tgt_ops->handle_io_background)
q->tgt_ops->handle_io_background(local_to_tq(q),
io_uring_sq_ready(&q->ring));
Expand Down
5 changes: 3 additions & 2 deletions lib/ublksrv_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(struct ublk_param_discard,
reserved0)

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(struct ublk_param_zoned,
max_open_zones,
max_active_zones)
max_open_zones,
max_active_zones,
max_zone_append_sectors)

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(struct ublk_params,
len, types, basic, discard, zoned)
Expand Down

0 comments on commit 7de0d90

Please sign in to comment.