master - bcache: Add sync io engine
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ae5037481172da84d414ca047408d9fb13955886 Commit: ae5037481172da84d414ca047408d9fb13955886 Parent: 67b80e2d9d9b437f18f909c9c09e4b286337b031 Author: Joe Thornber <[email protected]> AuthorDate: Thu May 10 14:29:26 2018 +0100 Committer: Joe Thornber <[email protected]> CommitterDate: Thu May 10 14:29:26 2018 +0100
bcache: Add sync io engine
Something to fall back to when testing.
--- lib/device/bcache.c | 92 +++++++++++++++++++++++++++++++++++++++++++- lib/device/bcache.h | 1 + test/unit/bcache_utils_t.c | 67 +++++++++++++++++++++++++++---- 3 files changed, 150 insertions(+), 10 deletions(-)
lib/device/bcache.c +91 -1
@@ -129,7 +129,6 @@ static struct control_block *_iocb_to_cb(struct iocb *icb)//---------------------------------------------------------------- -// FIXME: write a sync engine too struct async_engine {struct io_engine e;io_context_t aio_context;
@@ -281,6 +280,97 @@ struct io_engine *create_async_io_engine(void)//---------------------------------------------------------------- +struct sync_io { +struct dm_list list; +void *context; +int err; +}; + +struct sync_engine { +struct io_engine e; +struct dm_list complete; +}; + +static struct sync_engine *_to_sync (struct io_engine *e) +{ + return container_of(e, struct sync_engine, e); +} + +static void _sync_destroy (struct io_engine *ioe) +{ +struct sync_engine *e =_to_sync (ioe); +dm_free (e); +} + +static bool _sync_issue (struct io_engine *ioe,enum dir d,int fd, +sector_t sb,sector_t se,void *data,void *context) +{ +int r; +uint64_t len = (se - sb) *512 ; +struct sync_engine *e =_to_sync (ioe); +struct sync_io *io =malloc (sizeof (*io)); +if (!io) +return false; + + r =lseek (fd, sb *512 ,SEEK_SET ); +if (r <0 ) +return false; + +do { +if (d ==DIR_READ ) + r =read (fd, data, len); +else + r =write (fd, data, len); + + }while (r ==EINTR || r ==EAGAIN ); + +if (r != len) + r = -EIO ; + +dm_list_add (&e->complete, &io->list); + io->context = context; + io->err = r <0 ? r :0 ; + +return true; +} + +static bool _sync_wait (struct io_engine *ioe,io_complete_fn fn) +{ +struct sync_io *io, *tmp; +struct sync_engine *e =_to_sync (ioe); + + dm_list_iterate_items_safe(io, tmp, &e->complete) { +fn (io->context, io->err); +dm_list_del (&io->list); +dm_free (io); + } + +return true; +} + +static unsigned _sync_max_io (struct io_engine *e) +{ +return 1 ; +} + +struct io_engine *create_sync_io_engine (void ) +{ +struct sync_engine *e =dm_malloc (sizeof (*e)); + +if (!e) +return NULL ; + + e->e.destroy = _sync_destroy; + e->e.issue = _sync_issue; + e->e.wait = _sync_wait; + e->e.max_io = _sync_max_io; + +dm_list_init (&e->complete); +return &e->e; +} + +//---------------------------------------------------------------- +#define MIN_BLOCKS 16#define WRITEBACK_LOW_THRESHOLD_PERCENT 33#define WRITEBACK_HIGH_THRESHOLD_PERCENT 66
lib/device/bcache.h +1 -0
@@ -48,6 +48,7 @@ struct io_engine { };struct io_engine *create_async_io_engine (void ); +struct io_engine *create_sync_io_engine (void );/*----------------------------------------------------------------*/
test/unit/bcache_utils_t.c +58 -9
117 lines not on this page · raw message