#define WAIT_USEC 100000
#define MAX_WAIT_USEC (3 * 1000000)
-static int ublk_dev_prep(struct ublk_dev *dev)
+static int ublk_dev_prep(const struct dev_ctx *ctx, struct ublk_dev *dev)
{
int dev_id = dev->dev_info.dev_id;
unsigned int wait_usec = 0;
dev->fds[0] = fd;
if (dev->tgt.ops->init_tgt)
- ret = dev->tgt.ops->init_tgt(dev);
+ ret = dev->tgt.ops->init_tgt(ctx, dev);
if (ret)
close(dev->fds[0]);
return ret;
ublk_dbg(UBLK_DBG_DEV, "%s enter\n", __func__);
- ret = ublk_dev_prep(dev);
+ ret = ublk_dev_prep(ctx, dev);
if (ret)
return ret;
unsigned short refs; /* used by target code only */
int result;
+
+ unsigned short tgt_ios;
+ void *private_data;
};
struct ublk_tgt_ops {
const char *name;
- int (*init_tgt)(struct ublk_dev *);
+ int (*init_tgt)(const struct dev_ctx *ctx, struct ublk_dev *);
void (*deinit_tgt)(struct ublk_dev *);
int (*queue_io)(struct ublk_queue *, int tag);
int nr_fds;
int ctrl_fd;
struct io_uring ring;
+
+ void *private_data;
};
#ifndef offsetof
addr[1] = 0;
}
+static inline struct ublk_io *ublk_get_io(struct ublk_queue *q, unsigned tag)
+{
+ return &q->ios[tag];
+}
+
static inline int ublk_complete_io(struct ublk_queue *q, unsigned tag, int res)
{
struct ublk_io *io = &q->ios[tag];
return ublk_queue_io_cmd(q, io, tag);
}
+static inline void ublk_queued_tgt_io(struct ublk_queue *q, unsigned tag, int queued)
+{
+ if (queued < 0)
+ ublk_complete_io(q, tag, queued);
+ else {
+ struct ublk_io *io = ublk_get_io(q, tag);
+
+ q->io_inflight += queued;
+ io->tgt_ios = queued;
+ io->result = 0;
+ }
+}
+
+static inline int ublk_completed_tgt_io(struct ublk_queue *q, unsigned tag)
+{
+ struct ublk_io *io = ublk_get_io(q, tag);
+
+ q->io_inflight--;
+
+ return --io->tgt_ios == 0;
+}
+
static inline int ublk_queue_use_zc(const struct ublk_queue *q)
{
return q->state & UBLKSRV_ZC;
#include "kublk.h"
-static int ublk_null_tgt_init(struct ublk_dev *dev)
+static int ublk_null_tgt_init(const struct dev_ctx *ctx, struct ublk_dev *dev)
{
const struct ublksrv_ctrl_dev_info *info = &dev->dev_info;
unsigned long dev_size = 250UL << 30;