mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2024-12-28 16:53:49 +00:00
dm io: remove code duplication between sync_io and aysnc_io
The only difference between the code to setup and dispatch the io in sync_io() and async_io() is the sync argument to dispatch_io(), which is used to update the opf argument. Update the opf argument direcly in sync_io(), and remove the sync argument from dispatch_io(). Then, make sync_io() call async_io() instead of duplicting all of its code. Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
This commit is contained in:
parent
b0042ba768
commit
babe69e86d
@ -384,16 +384,13 @@ static void do_region(const blk_opf_t opf, unsigned int region,
|
||||
|
||||
static void dispatch_io(blk_opf_t opf, unsigned int num_regions,
|
||||
struct dm_io_region *where, struct dpages *dp,
|
||||
struct io *io, int sync, unsigned short ioprio)
|
||||
struct io *io, unsigned short ioprio)
|
||||
{
|
||||
int i;
|
||||
struct dpages old_pages = *dp;
|
||||
|
||||
BUG_ON(num_regions > DM_IO_MAX_REGIONS);
|
||||
|
||||
if (sync)
|
||||
opf |= REQ_SYNC;
|
||||
|
||||
/*
|
||||
* For multiple regions we need to be careful to rewind
|
||||
* the dp object for each call to do_region.
|
||||
@ -411,48 +408,6 @@ static void dispatch_io(blk_opf_t opf, unsigned int num_regions,
|
||||
dec_count(io, 0, 0);
|
||||
}
|
||||
|
||||
struct sync_io {
|
||||
unsigned long error_bits;
|
||||
struct completion wait;
|
||||
};
|
||||
|
||||
static void sync_io_complete(unsigned long error, void *context)
|
||||
{
|
||||
struct sync_io *sio = context;
|
||||
|
||||
sio->error_bits = error;
|
||||
complete(&sio->wait);
|
||||
}
|
||||
|
||||
static int sync_io(struct dm_io_client *client, unsigned int num_regions,
|
||||
struct dm_io_region *where, blk_opf_t opf, struct dpages *dp,
|
||||
unsigned long *error_bits, unsigned short ioprio)
|
||||
{
|
||||
struct io *io;
|
||||
struct sync_io sio;
|
||||
|
||||
init_completion(&sio.wait);
|
||||
|
||||
io = mempool_alloc(&client->pool, GFP_NOIO);
|
||||
io->error_bits = 0;
|
||||
atomic_set(&io->count, 1); /* see dispatch_io() */
|
||||
io->client = client;
|
||||
io->callback = sync_io_complete;
|
||||
io->context = &sio;
|
||||
|
||||
io->vma_invalidate_address = dp->vma_invalidate_address;
|
||||
io->vma_invalidate_size = dp->vma_invalidate_size;
|
||||
|
||||
dispatch_io(opf, num_regions, where, dp, io, 1, ioprio);
|
||||
|
||||
wait_for_completion_io(&sio.wait);
|
||||
|
||||
if (error_bits)
|
||||
*error_bits = sio.error_bits;
|
||||
|
||||
return sio.error_bits ? -EIO : 0;
|
||||
}
|
||||
|
||||
static void async_io(struct dm_io_client *client, unsigned int num_regions,
|
||||
struct dm_io_region *where, blk_opf_t opf,
|
||||
struct dpages *dp, io_notify_fn fn, void *context,
|
||||
@ -470,7 +425,39 @@ static void async_io(struct dm_io_client *client, unsigned int num_regions,
|
||||
io->vma_invalidate_address = dp->vma_invalidate_address;
|
||||
io->vma_invalidate_size = dp->vma_invalidate_size;
|
||||
|
||||
dispatch_io(opf, num_regions, where, dp, io, 0, ioprio);
|
||||
dispatch_io(opf, num_regions, where, dp, io, ioprio);
|
||||
}
|
||||
|
||||
struct sync_io {
|
||||
unsigned long error_bits;
|
||||
struct completion wait;
|
||||
};
|
||||
|
||||
static void sync_io_complete(unsigned long error, void *context)
|
||||
{
|
||||
struct sync_io *sio = context;
|
||||
|
||||
sio->error_bits = error;
|
||||
complete(&sio->wait);
|
||||
}
|
||||
|
||||
static int sync_io(struct dm_io_client *client, unsigned int num_regions,
|
||||
struct dm_io_region *where, blk_opf_t opf, struct dpages *dp,
|
||||
unsigned long *error_bits, unsigned short ioprio)
|
||||
{
|
||||
struct sync_io sio;
|
||||
|
||||
init_completion(&sio.wait);
|
||||
|
||||
async_io(client, num_regions, where, opf | REQ_SYNC, dp,
|
||||
sync_io_complete, &sio, ioprio);
|
||||
|
||||
wait_for_completion_io(&sio.wait);
|
||||
|
||||
if (error_bits)
|
||||
*error_bits = sio.error_bits;
|
||||
|
||||
return sio.error_bits ? -EIO : 0;
|
||||
}
|
||||
|
||||
static int dp_init(struct dm_io_request *io_req, struct dpages *dp,
|
||||
|
Loading…
Reference in New Issue
Block a user