lib/ftl: Add ftl_io argument to internal I/O callbacks

Almost all I/O callbacks in ftl utilize data in ftl_io, which is
initialized as callback argument in ftl_io_init_internal. This patch
changes the behavior to always returning the ftl_io struct in addition
to an extra opaque buffer.

Signed-off-by: Mateusz Kozlowski <mateusz.kozlowski@intel.com>
Change-Id: I611ab1b33575f599798a2bb65c231a724c852c7f
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/455831
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: Wojciech Malikowski <wojciech.malikowski@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Mateusz Kozlowski 2019-05-27 14:56:48 +02:00 committed by Ben Walker
parent 5875bb0e3b
commit e49ae312b1
10 changed files with 112 additions and 116 deletions

View File

@ -722,9 +722,9 @@ ftl_band_release_lba_map(struct ftl_band *band)
}
static void
ftl_read_md_cb(void *arg, int status)
ftl_read_md_cb(struct ftl_io *io, void *arg, int status)
{
struct ftl_md_io *md_io = arg;
struct ftl_md_io *md_io = (struct ftl_md_io *)io;
if (!status) {
status = md_io->pack_fn(md_io->io.band);
@ -732,13 +732,13 @@ ftl_read_md_cb(void *arg, int status)
status = FTL_MD_IO_FAILURE;
}
md_io->cb.fn(md_io->cb.ctx, status);
md_io->cb_fn(io, md_io->cb_ctx, status);
}
static struct ftl_md_io *
ftl_io_init_md_read(struct spdk_ftl_dev *dev, struct ftl_ppa ppa,
struct ftl_band *band, size_t lbk_cnt, spdk_ftl_fn fn,
ftl_md_pack_fn pack_fn, struct ftl_cb cb)
struct ftl_band *band, size_t lbk_cnt, ftl_io_fn fn,
ftl_md_pack_fn pack_fn, ftl_io_fn cb_fn, void *cb_ctx)
{
struct ftl_md_io *io;
struct ftl_io_init_opts opts = {
@ -750,7 +750,7 @@ ftl_io_init_md_read(struct spdk_ftl_dev *dev, struct ftl_ppa ppa,
.flags = FTL_IO_MD | FTL_IO_PPA_MODE,
.type = FTL_IO_READ,
.lbk_cnt = lbk_cnt,
.fn = fn,
.cb_fn = fn,
.data = band->lba_map.dma_buf,
};
@ -761,14 +761,15 @@ ftl_io_init_md_read(struct spdk_ftl_dev *dev, struct ftl_ppa ppa,
io->io.ppa = ppa;
io->pack_fn = pack_fn;
io->cb = cb;
io->cb_fn = cb_fn;
io->cb_ctx = cb_ctx;
return io;
}
static struct ftl_io *
ftl_io_init_md_write(struct spdk_ftl_dev *dev, struct ftl_band *band,
void *data, size_t lbk_cnt, spdk_ftl_fn cb)
void *data, size_t lbk_cnt, ftl_io_fn cb)
{
struct ftl_io_init_opts opts = {
.dev = dev,
@ -779,7 +780,7 @@ ftl_io_init_md_write(struct spdk_ftl_dev *dev, struct ftl_band *band,
.flags = FTL_IO_MD | FTL_IO_PPA_MODE,
.type = FTL_IO_WRITE,
.lbk_cnt = lbk_cnt,
.fn = cb,
.cb_fn = cb,
.data = data,
.md = NULL,
};
@ -789,7 +790,7 @@ ftl_io_init_md_write(struct spdk_ftl_dev *dev, struct ftl_band *band,
static int
ftl_band_write_md(struct ftl_band *band, size_t lbk_cnt,
ftl_md_pack_fn md_fn, spdk_ftl_fn cb)
ftl_md_pack_fn md_fn, ftl_io_fn cb)
{
struct spdk_ftl_dev *dev = band->dev;
struct ftl_io *io;
@ -815,14 +816,14 @@ ftl_band_md_clear(struct ftl_band *band)
}
int
ftl_band_write_head_md(struct ftl_band *band, spdk_ftl_fn cb)
ftl_band_write_head_md(struct ftl_band *band, ftl_io_fn cb)
{
return ftl_band_write_md(band, ftl_head_md_num_lbks(band->dev),
ftl_pack_head_md, cb);
}
int
ftl_band_write_tail_md(struct ftl_band *band, spdk_ftl_fn cb)
ftl_band_write_tail_md(struct ftl_band *band, ftl_io_fn cb)
{
return ftl_band_write_md(band, ftl_tail_md_num_lbks(band->dev),
ftl_pack_tail_md, cb);
@ -839,7 +840,7 @@ ftl_band_lba_map_ppa(struct ftl_band *band, size_t offset)
static int
ftl_band_read_md(struct ftl_band *band, size_t lbk_cnt, struct ftl_ppa start_ppa,
spdk_ftl_fn fn, ftl_md_pack_fn pack_fn, struct ftl_cb cb)
ftl_io_fn fn, ftl_md_pack_fn pack_fn, ftl_io_fn cb_fn, void *cb_ctx)
{
struct spdk_ftl_dev *dev = band->dev;
struct ftl_md_io *io;
@ -848,7 +849,7 @@ ftl_band_read_md(struct ftl_band *band, size_t lbk_cnt, struct ftl_ppa start_ppa
return -ENOENT;
}
io = ftl_io_init_md_read(dev, start_ppa, band, lbk_cnt, fn, pack_fn, cb);
io = ftl_io_init_md_read(dev, start_ppa, band, lbk_cnt, fn, pack_fn, cb_fn, cb_ctx);
if (!io) {
return -ENOMEM;
}
@ -858,10 +859,10 @@ ftl_band_read_md(struct ftl_band *band, size_t lbk_cnt, struct ftl_ppa start_ppa
}
int
ftl_band_read_tail_md(struct ftl_band *band, struct ftl_ppa ppa, struct ftl_cb cb)
ftl_band_read_tail_md(struct ftl_band *band, struct ftl_ppa ppa, ftl_io_fn cb_fn, void *cb_ctx)
{
return ftl_band_read_md(band, ftl_tail_md_num_lbks(band->dev), ppa,
ftl_read_md_cb, ftl_unpack_tail_md, cb);
ftl_read_md_cb, ftl_unpack_tail_md, cb_fn, cb_ctx);
}
static size_t
@ -877,10 +878,9 @@ ftl_lba_map_offset_from_ppa(struct ftl_band *band, struct ftl_ppa ppa)
}
static void
ftl_read_lba_map_cb(void *arg, int status)
ftl_read_lba_map_cb(struct ftl_io *io, void *arg, int status)
{
struct ftl_md_io *md_io = arg;
struct ftl_io *io = &md_io->io;
struct ftl_md_io *md_io = (struct ftl_md_io *)io;
struct ftl_lba_map *lba_map = &io->band->lba_map;
uint64_t offset;
@ -892,12 +892,12 @@ ftl_read_lba_map_cb(void *arg, int status)
io->lbk_cnt * FTL_BLOCK_SIZE);
}
md_io->cb.fn(md_io->cb.ctx, status);
md_io->cb_fn(io, md_io->cb_ctx, status);
}
int
ftl_band_read_lba_map(struct ftl_band *band, size_t offset, size_t lba_cnt,
struct ftl_cb cb)
ftl_io_fn cb_fn, void *cb_ctx)
{
size_t lbk_cnt, lbk_off;
@ -907,18 +907,19 @@ ftl_band_read_lba_map(struct ftl_band *band, size_t offset, size_t lba_cnt,
assert(lbk_off + lbk_cnt <= ftl_lba_map_num_lbks(band->dev));
return ftl_band_read_md(band, lbk_cnt, ftl_band_lba_map_ppa(band, lbk_off),
ftl_read_lba_map_cb, NULL, cb);
ftl_read_lba_map_cb, NULL, cb_fn, cb_ctx);
}
int
ftl_band_read_head_md(struct ftl_band *band, struct ftl_cb cb)
ftl_band_read_head_md(struct ftl_band *band, ftl_io_fn cb_fn, void *cb_ctx)
{
return ftl_band_read_md(band,
ftl_head_md_num_lbks(band->dev),
ftl_band_head_md_ppa(band),
ftl_read_md_cb,
ftl_unpack_head_md,
cb);
cb_fn,
cb_ctx);
}
static void
@ -943,9 +944,8 @@ ftl_erase_fail(struct ftl_io *io, int status)
}
static void
ftl_band_erase_cb(void *ctx, int status)
ftl_band_erase_cb(struct ftl_io *io, void *ctx, int status)
{
struct ftl_io *io = ctx;
struct ftl_chunk *chunk;
if (spdk_unlikely(status)) {

View File

@ -38,10 +38,10 @@
#include "spdk/bit_array.h"
#include "spdk/queue.h"
#include "ftl_io.h"
#include "ftl_ppa.h"
struct spdk_ftl_dev;
struct ftl_cb;
enum ftl_chunk_state {
FTL_CHUNK_STATE_FREE,
@ -170,7 +170,7 @@ void ftl_band_clear_lba_map(struct ftl_band *band);
void ftl_band_release_lba_map(struct ftl_band *band);
int ftl_band_read_lba_map(struct ftl_band *band,
size_t offset, size_t lba_cnt,
struct ftl_cb cb);
ftl_io_fn cb_fn, void *cb_ctx);
struct ftl_ppa ftl_band_next_xfer_ppa(struct ftl_band *band, struct ftl_ppa ppa,
size_t num_lbks);
struct ftl_ppa ftl_band_next_ppa(struct ftl_band *band, struct ftl_ppa ppa,
@ -184,10 +184,10 @@ struct ftl_band *ftl_band_from_ppa(struct spdk_ftl_dev *dev, struct ftl_ppa ppa)
struct ftl_chunk *ftl_band_chunk_from_ppa(struct ftl_band *band, struct ftl_ppa);
void ftl_band_md_clear(struct ftl_band *band);
int ftl_band_read_tail_md(struct ftl_band *band, struct ftl_ppa,
struct ftl_cb cb);
int ftl_band_read_head_md(struct ftl_band *band, struct ftl_cb cb);
int ftl_band_write_tail_md(struct ftl_band *band, spdk_ftl_fn cb);
int ftl_band_write_head_md(struct ftl_band *band, spdk_ftl_fn cb);
ftl_io_fn cb_fn, void *cb_ctx);
int ftl_band_read_head_md(struct ftl_band *band, ftl_io_fn cb_fn, void *cb_ctx);
int ftl_band_write_tail_md(struct ftl_band *band, ftl_io_fn cb);
int ftl_band_write_head_md(struct ftl_band *band, ftl_io_fn cb);
struct ftl_ppa ftl_band_tail_md_ppa(struct ftl_band *band);
struct ftl_ppa ftl_band_head_md_ppa(struct ftl_band *band);
void ftl_band_write_failed(struct ftl_band *band);

View File

@ -79,7 +79,10 @@ struct ftl_flush {
size_t num_req;
/* Callback */
struct ftl_cb cb;
struct {
spdk_ftl_fn fn;
void *ctx;
} cb;
/* Batch bitmap */
struct spdk_bit_array *bmap;
@ -189,9 +192,8 @@ ftl_md_write_fail(struct ftl_io *io, int status)
}
static void
ftl_md_write_cb(void *arg, int status)
ftl_md_write_cb(struct ftl_io *io, void *arg, int status)
{
struct ftl_io *io = arg;
struct spdk_ftl_dev *dev = io->dev;
struct ftl_nv_cache *nv_cache = &dev->nv_cache;
struct ftl_wptr *wptr;
@ -1055,9 +1057,8 @@ ftl_write_fail(struct ftl_io *io, int status)
}
static void
ftl_write_cb(void *arg, int status)
ftl_write_cb(struct ftl_io *io, void *arg, int status)
{
struct ftl_io *io = arg;
struct spdk_ftl_dev *dev = io->dev;
struct ftl_rwb_batch *batch = io->rwb_batch;
struct ftl_rwb_entry *entry;
@ -1157,7 +1158,7 @@ ftl_update_l2p(struct spdk_ftl_dev *dev, const struct ftl_rwb_entry *entry,
static struct ftl_io *
ftl_io_init_child_write(struct ftl_io *parent, struct ftl_ppa ppa,
void *data, void *md, spdk_ftl_fn cb)
void *data, void *md, ftl_io_fn cb)
{
struct ftl_io *io;
struct spdk_ftl_dev *dev = parent->dev;
@ -1171,7 +1172,7 @@ ftl_io_init_child_write(struct ftl_io *parent, struct ftl_ppa ppa,
.flags = 0,
.type = FTL_IO_WRITE,
.lbk_cnt = dev->xfer_size,
.fn = cb,
.cb_fn = cb,
.data = data,
.md = md,
};
@ -1187,10 +1188,9 @@ ftl_io_init_child_write(struct ftl_io *parent, struct ftl_ppa ppa,
}
static void
ftl_io_child_write_cb(void *ctx, int status)
ftl_io_child_write_cb(struct ftl_io *io, void *ctx, int status)
{
struct ftl_chunk *chunk;
struct ftl_io *io = ctx;
chunk = ftl_band_chunk_from_ppa(io->band, io->ppa);
chunk->busy = false;

View File

@ -256,15 +256,15 @@ ftl_io_shrink_iovec(struct ftl_io *io, size_t lbk_cnt)
static void
ftl_io_init(struct ftl_io *io, struct spdk_ftl_dev *dev,
spdk_ftl_fn fn, void *ctx, int flags, int type)
ftl_io_fn fn, void *ctx, int flags, int type)
{
io->flags |= flags | FTL_IO_INITIALIZED;
io->type = type;
io->dev = dev;
io->lba.single = FTL_LBA_INVALID;
io->ppa.ppa = FTL_PPA_INVALID;
io->cb.fn = fn;
io->cb.ctx = ctx;
io->cb_fn = fn;
io->cb_ctx = ctx;
io->trace = ftl_trace_alloc_id(dev);
}
@ -291,7 +291,7 @@ ftl_io_init_internal(const struct ftl_io_init_opts *opts)
}
ftl_io_clear(io);
ftl_io_init(io, dev, opts->fn, io, opts->flags | FTL_IO_INTERNAL, opts->type);
ftl_io_init(io, dev, opts->cb_fn, opts->cb_ctx, opts->flags | FTL_IO_INTERNAL, opts->type);
io->rwb_batch = opts->rwb_batch;
io->band = opts->band;
@ -309,7 +309,7 @@ ftl_io_init_internal(const struct ftl_io_init_opts *opts)
struct ftl_io *
ftl_io_rwb_init(struct spdk_ftl_dev *dev, struct ftl_band *band,
struct ftl_rwb_batch *batch, spdk_ftl_fn cb)
struct ftl_rwb_batch *batch, ftl_io_fn cb)
{
struct ftl_io_init_opts opts = {
.dev = dev,
@ -320,7 +320,7 @@ ftl_io_rwb_init(struct spdk_ftl_dev *dev, struct ftl_band *band,
.flags = 0,
.type = FTL_IO_WRITE,
.lbk_cnt = dev->xfer_size,
.fn = cb,
.cb_fn = cb,
.data = ftl_rwb_batch_get_data(batch),
.md = ftl_rwb_batch_get_md(batch),
};
@ -329,7 +329,7 @@ ftl_io_rwb_init(struct spdk_ftl_dev *dev, struct ftl_band *band,
}
struct ftl_io *
ftl_io_erase_init(struct ftl_band *band, size_t lbk_cnt, spdk_ftl_fn cb)
ftl_io_erase_init(struct ftl_band *band, size_t lbk_cnt, ftl_io_fn cb)
{
struct ftl_io *io;
struct ftl_io_init_opts opts = {
@ -341,7 +341,7 @@ ftl_io_erase_init(struct ftl_band *band, size_t lbk_cnt, spdk_ftl_fn cb)
.flags = FTL_IO_PPA_MODE,
.type = FTL_IO_ERASE,
.lbk_cnt = 1,
.fn = cb,
.cb_fn = cb,
.data = NULL,
.md = NULL,
};
@ -356,9 +356,15 @@ ftl_io_erase_init(struct ftl_band *band, size_t lbk_cnt, spdk_ftl_fn cb)
return io;
}
static void
_ftl_user_cb(struct ftl_io *io, void *arg, int status)
{
io->user_fn(arg, status);
}
struct ftl_io *
ftl_io_user_init(struct spdk_io_channel *_ioch, uint64_t lba, size_t lbk_cnt, struct iovec *iov,
size_t iov_cnt, spdk_ftl_fn cb_fn, void *cb_arg, int type)
size_t iov_cnt, spdk_ftl_fn cb_fn, void *cb_ctx, int type)
{
struct ftl_io_channel *ioch = spdk_io_channel_get_ctx(_ioch);
struct spdk_ftl_dev *dev = ioch->dev;
@ -369,8 +375,9 @@ ftl_io_user_init(struct spdk_io_channel *_ioch, uint64_t lba, size_t lbk_cnt, st
return NULL;
}
ftl_io_init(io, dev, cb_fn, cb_arg, 0, type);
ftl_io_init(io, dev, _ftl_user_cb, cb_ctx, 0, type);
io->lba.single = lba;
io->user_fn = cb_fn;
if (ftl_io_init_iovec(io, iov, iov_cnt, lbk_cnt)) {
ftl_io_free(io);
@ -425,8 +432,8 @@ ftl_io_complete(struct ftl_io *io)
pthread_spin_unlock(&io->lock);
if (complete) {
if (io->cb.fn) {
io->cb.fn(io->cb.ctx, io->status);
if (io->cb_fn) {
io->cb_fn(io, io->cb_ctx, io->status);
}
if (parent && ftl_io_remove_child(io)) {
@ -511,10 +518,10 @@ ftl_io_alloc(struct spdk_io_channel *ch)
}
void
ftl_io_reinit(struct ftl_io *io, spdk_ftl_fn fn, void *ctx, int flags, int type)
ftl_io_reinit(struct ftl_io *io, ftl_io_fn cb, void *ctx, int flags, int type)
{
ftl_io_clear(io);
ftl_io_init(io, io->dev, fn, ctx, flags, type);
ftl_io_init(io, io->dev, cb, ctx, flags, type);
}
void

View File

@ -47,6 +47,7 @@ struct ftl_band;
struct ftl_io;
typedef int (*ftl_md_pack_fn)(struct ftl_band *);
typedef void (*ftl_io_fn)(struct ftl_io *, void *, int);
/* IO flags */
enum ftl_io_flags {
@ -112,16 +113,11 @@ struct ftl_io_init_opts {
/* Metadata */
void *md;
/* Callback */
spdk_ftl_fn fn;
};
struct ftl_cb {
/* Callback function */
spdk_ftl_fn fn;
/* Callback's function */
ftl_io_fn cb_fn;
/* Callback's context */
void *ctx;
void *cb_ctx;
};
struct ftl_io_channel {
@ -187,8 +183,14 @@ struct ftl_io {
/* Number of split requests */
size_t req_cnt;
/* Completion callback */
struct ftl_cb cb;
/* Callback's function */
ftl_io_fn cb_fn;
/* Callback's context */
void *cb_ctx;
/* User callback function */
spdk_ftl_fn user_fn;
/* Flags */
int flags;
@ -222,8 +224,11 @@ struct ftl_md_io {
/* Serialization/deserialization callback */
ftl_md_pack_fn pack_fn;
/* User's callback */
struct ftl_cb cb;
/* Callback's function */
ftl_io_fn cb_fn;
/* Callback's context */
void *cb_ctx;
};
static inline bool
@ -251,7 +256,7 @@ struct ftl_io *ftl_io_alloc_child(struct ftl_io *parent);
void ftl_io_fail(struct ftl_io *io, int status);
void ftl_io_free(struct ftl_io *io);
struct ftl_io *ftl_io_init_internal(const struct ftl_io_init_opts *opts);
void ftl_io_reinit(struct ftl_io *io, spdk_ftl_fn cb,
void ftl_io_reinit(struct ftl_io *io, ftl_io_fn cb,
void *ctx, int flags, int type);
void ftl_io_clear(struct ftl_io *io);
void ftl_io_inc_req(struct ftl_io *io);
@ -264,8 +269,8 @@ size_t ftl_iovec_num_lbks(struct iovec *iov, size_t iov_cnt);
void *ftl_io_iovec_addr(struct ftl_io *io);
size_t ftl_io_iovec_len_left(struct ftl_io *io);
struct ftl_io *ftl_io_rwb_init(struct spdk_ftl_dev *dev, struct ftl_band *band,
struct ftl_rwb_batch *entry, spdk_ftl_fn cb);
struct ftl_io *ftl_io_erase_init(struct ftl_band *band, size_t lbk_cnt, spdk_ftl_fn cb);
struct ftl_rwb_batch *entry, ftl_io_fn cb);
struct ftl_io *ftl_io_erase_init(struct ftl_band *band, size_t lbk_cnt, ftl_io_fn cb);
struct ftl_io *ftl_io_user_init(struct spdk_io_channel *ioch, uint64_t lba, size_t lbk_cnt,
struct iovec *iov, size_t iov_cnt, spdk_ftl_fn cb_fn,
void *cb_arg, int type);

View File

@ -163,13 +163,11 @@ _ftl_reloc_prep(struct ftl_band_reloc *breloc)
}
static void
ftl_reloc_read_lba_map_cb(void *arg, int status)
ftl_reloc_read_lba_map_cb(struct ftl_io *io, void *arg, int status)
{
struct ftl_io *io = arg;
struct ftl_band_reloc *breloc = ftl_io_get_band_reloc(io);
struct ftl_band_reloc *breloc = arg;
assert(status == 0);
ftl_io_free(io);
_ftl_reloc_prep(breloc);
}
@ -178,18 +176,12 @@ ftl_reloc_read_lba_map(struct ftl_band_reloc *breloc)
{
struct ftl_band *band = breloc->band;
struct spdk_ftl_dev *dev = band->dev;
struct ftl_io *io = ftl_io_alloc(dev->ioch);
io->dev = dev;
io->band = band;
io->cb.ctx = io;
io->cb.fn = ftl_reloc_read_lba_map_cb;
if (ftl_band_alloc_lba_map(band)) {
assert(false);
}
return ftl_band_read_lba_map(band, 0, ftl_num_band_lbks(dev), io->cb);
return ftl_band_read_lba_map(band, 0, ftl_num_band_lbks(dev), ftl_reloc_read_lba_map_cb, breloc);
}
static void
@ -219,9 +211,8 @@ ftl_reloc_free_io(struct ftl_band_reloc *breloc, struct ftl_io *io)
}
static void
ftl_reloc_write_cb(void *arg, int status)
ftl_reloc_write_cb(struct ftl_io *io, void *arg, int status)
{
struct ftl_io *io = arg;
struct ftl_ppa ppa = io->ppa;
struct ftl_band_reloc *breloc = ftl_io_get_band_reloc(io);
size_t i;
@ -242,9 +233,8 @@ ftl_reloc_write_cb(void *arg, int status)
}
static void
ftl_reloc_read_cb(void *arg, int status)
ftl_reloc_read_cb(struct ftl_io *io, void *arg, int status)
{
struct ftl_io *io = arg;
struct ftl_band_reloc *breloc = ftl_io_get_band_reloc(io);
/* TODO: We should handle fail on relocation read. We need to inform */
@ -384,13 +374,13 @@ ftl_reloc_next_lbks(struct ftl_band_reloc *breloc, struct ftl_ppa *ppa)
static void
ftl_reloc_io_reinit(struct ftl_io *io, struct ftl_band_reloc *breloc,
spdk_ftl_fn fn, enum ftl_io_type io_type, int flags)
ftl_io_fn fn, enum ftl_io_type io_type, int flags)
{
size_t i;
uint64_t lbkoff;
struct ftl_ppa ppa = io->ppa;
ftl_io_reinit(io, fn, io, flags | FTL_IO_INTERNAL, io_type);
ftl_io_reinit(io, fn, NULL, flags | FTL_IO_INTERNAL, io_type);
io->ppa = ppa;
io->band = breloc->band;
@ -437,7 +427,7 @@ ftl_reloc_io_init(struct ftl_band_reloc *breloc, struct ftl_io *io,
.flags = FTL_IO_KEEP_ALIVE | FTL_IO_INTERNAL | FTL_IO_PPA_MODE,
.type = FTL_IO_READ,
.lbk_cnt = num_lbks,
.fn = ftl_reloc_read_cb,
.cb_fn = ftl_reloc_read_cb,
};
opts.data = spdk_dma_malloc(PAGE_SIZE * num_lbks, PAGE_SIZE, NULL);

View File

@ -236,7 +236,7 @@ out:
}
static void
ftl_restore_head_cb(void *ctx, int status)
ftl_restore_head_cb(struct ftl_io *io, void *ctx, int status)
{
struct ftl_restore_band *rband = ctx;
struct ftl_restore *restore = rband->parent;
@ -257,21 +257,18 @@ ftl_restore_head_md(struct ftl_restore *restore)
struct spdk_ftl_dev *dev = restore->dev;
struct ftl_restore_band *rband;
struct ftl_lba_map *lba_map;
struct ftl_cb cb;
unsigned int num_failed = 0, num_ios;
size_t i;
cb.fn = ftl_restore_head_cb;
restore->num_ios = ftl_dev_num_bands(dev);
for (i = 0; i < ftl_dev_num_bands(dev); ++i) {
rband = &restore->bands[i];
lba_map = &rband->band->lba_map;
cb.ctx = rband;
lba_map->dma_buf = restore->md_buf + i * ftl_head_md_num_lbks(dev) * FTL_BLOCK_SIZE;
if (ftl_band_read_head_md(rband->band, cb)) {
if (ftl_band_read_head_md(rband->band, ftl_restore_head_cb, rband)) {
if (spdk_likely(rband->band->num_chunks)) {
SPDK_ERRLOG("Failed to read metadata on band %zu\n", i);
@ -364,7 +361,7 @@ ftl_restore_next_band(struct ftl_restore *restore)
}
static void
ftl_restore_tail_md_cb(void *ctx, int status)
ftl_restore_tail_md_cb(struct ftl_io *io, void *ctx, int status)
{
struct ftl_restore_band *rband = ctx;
struct ftl_restore *restore = rband->parent;
@ -393,15 +390,12 @@ ftl_restore_tail_md(struct ftl_restore_band *rband)
{
struct ftl_restore *restore = rband->parent;
struct ftl_band *band = rband->band;
struct ftl_cb cb = { .fn = ftl_restore_tail_md_cb,
.ctx = rband
};
band->tail_md_ppa = ftl_band_tail_md_ppa(band);
band->lba_map.map = restore->lba_map;
band->lba_map.dma_buf = restore->md_buf;
if (ftl_band_read_tail_md(band, band->tail_md_ppa, cb)) {
if (ftl_band_read_tail_md(band, band->tail_md_ppa, ftl_restore_tail_md_cb, rband)) {
SPDK_ERRLOG("Failed to send tail metadata read\n");
ftl_restore_complete(restore, -EIO);
return -EIO;

View File

@ -76,15 +76,15 @@ free_device(struct spdk_ftl_dev *dev)
}
static void
setup_io(struct ftl_io *io, struct spdk_ftl_dev *dev, spdk_ftl_fn cb, void *ctx)
setup_io(struct ftl_io *io, struct spdk_ftl_dev *dev, ftl_io_fn cb, void *ctx)
{
io->dev = dev;
io->cb.fn = cb;
io->cb.ctx = ctx;
io->cb_fn = cb;
io->cb_ctx = ctx;
}
static struct ftl_io *
alloc_io(struct spdk_ftl_dev *dev, spdk_ftl_fn cb, void *ctx)
alloc_io(struct spdk_ftl_dev *dev, ftl_io_fn cb, void *ctx)
{
struct ftl_io *io;
@ -96,7 +96,7 @@ alloc_io(struct spdk_ftl_dev *dev, spdk_ftl_fn cb, void *ctx)
}
static void
io_complete_cb(void *ctx, int status)
io_complete_cb(struct ftl_io *io, void *ctx, int status)
{
*(int *)ctx = status;
}

View File

@ -95,9 +95,9 @@ ftl_lba_map_num_lbks(const struct spdk_ftl_dev *dev)
int
ftl_band_read_lba_map(struct ftl_band *band, size_t offset,
size_t lbk_cnt, struct ftl_cb cb)
size_t lbk_cnt, ftl_io_fn fn, void *ctx)
{
cb.fn(cb.ctx, 0);
fn(ctx, ctx, 0);
return 0;
}
@ -127,13 +127,13 @@ ftl_band_ppa_from_lbkoff(struct ftl_band *band, uint64_t lbkoff)
void
ftl_io_read(struct ftl_io *io)
{
io->cb.fn(io->cb.ctx, 0);
io->cb_fn(io, io->cb_ctx, 0);
}
void
ftl_io_write(struct ftl_io *io)
{
io->cb.fn(io->cb.ctx, 0);
io->cb_fn(io, io->cb_ctx, 0);
}
struct ftl_io *
@ -150,8 +150,8 @@ ftl_io_init_internal(const struct ftl_io_init_opts *opts)
io->dev = opts->dev;
io->band = opts->band;
io->flags = opts->flags;
io->cb.fn = opts->fn;
io->cb.ctx = io;
io->cb_fn = opts->cb_fn;
io->cb_ctx = io;
io->lbk_cnt = opts->lbk_cnt;
io->iov[0].iov_base = opts->data;
return io;
@ -172,10 +172,10 @@ ftl_io_free(struct ftl_io *io)
}
void
ftl_io_reinit(struct ftl_io *io, spdk_ftl_fn fn, void *ctx, int flags, int type)
ftl_io_reinit(struct ftl_io *io, ftl_io_fn fn, void *ctx, int flags, int type)
{
io->cb.fn = fn;
io->cb.ctx = ctx;
io->cb_fn = fn;
io->cb_ctx = ctx;
io->type = type;
}

View File

@ -80,7 +80,7 @@ DEFINE_STUB(spdk_bdev_desc_get_bdev, struct spdk_bdev *, (struct spdk_bdev_desc
DEFINE_STUB(spdk_bdev_get_num_blocks, uint64_t, (const struct spdk_bdev *bdev), 0);
struct ftl_io *
ftl_io_erase_init(struct ftl_band *band, size_t lbk_cnt, spdk_ftl_fn cb)
ftl_io_erase_init(struct ftl_band *band, size_t lbk_cnt, ftl_io_fn cb)
{
struct ftl_io *io;
@ -89,7 +89,7 @@ ftl_io_erase_init(struct ftl_band *band, size_t lbk_cnt, spdk_ftl_fn cb)
io->dev = band->dev;
io->band = band;
io->cb.fn = cb;
io->cb_fn = cb;
io->lbk_cnt = 1;
return io;
@ -104,7 +104,7 @@ ftl_io_advance(struct ftl_io *io, size_t lbk_cnt)
void
ftl_io_complete(struct ftl_io *io)
{
io->cb.fn(io, 0);
io->cb_fn(io, NULL, 0);
free(io);
}
@ -177,7 +177,7 @@ test_wptr(void)
/* Call the metadata completion cb to force band state change */
/* and removal of the actual wptr */
ftl_md_write_cb(&io, 0);
ftl_md_write_cb(&io, NULL, 0);
CU_ASSERT_EQUAL(band->state, FTL_BAND_STATE_CLOSED);
CU_ASSERT_TRUE(LIST_EMPTY(&dev->wptr_list));