Commit b0042ba7 authored by Benjamin Marzinski's avatar Benjamin Marzinski Committed by Mikulas Patocka

dm io: don't call the async_io notify.fn on invalid num_regions

If dm_io() returned an error, callers that set a notify.fn and wanted it
called on an error need to check the return value and call notify.fn
themselves if it was -EINVAL but not if it was -EIO. None of them do
this (granted, all the existing async_io users of dm_io call it in a way
that is guaranteed to not return an error).

Simplify the interface by never calling the notify.fn if dm_io returns
an error. This works with the existing dm_io callers which check for an
error and handle it using the same methods as the notify.fn.

This also allows us to move the now equivalent num_regions checks out of
sync_io() and async_io() and into dm_io() itself. Additionally, change
async_io() into a void function, since it can no longer fail.
Signed-off-by: default avatarBenjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
parent 06a0b333
...@@ -431,11 +431,6 @@ static int sync_io(struct dm_io_client *client, unsigned int num_regions, ...@@ -431,11 +431,6 @@ static int sync_io(struct dm_io_client *client, unsigned int num_regions,
struct io *io; struct io *io;
struct sync_io sio; struct sync_io sio;
if (num_regions > 1 && !op_is_write(opf)) {
WARN_ON(1);
return -EIO;
}
init_completion(&sio.wait); init_completion(&sio.wait);
io = mempool_alloc(&client->pool, GFP_NOIO); io = mempool_alloc(&client->pool, GFP_NOIO);
...@@ -458,19 +453,13 @@ static int sync_io(struct dm_io_client *client, unsigned int num_regions, ...@@ -458,19 +453,13 @@ static int sync_io(struct dm_io_client *client, unsigned int num_regions,
return sio.error_bits ? -EIO : 0; return sio.error_bits ? -EIO : 0;
} }
static int async_io(struct dm_io_client *client, unsigned int num_regions, static void async_io(struct dm_io_client *client, unsigned int num_regions,
struct dm_io_region *where, blk_opf_t opf, struct dm_io_region *where, blk_opf_t opf,
struct dpages *dp, io_notify_fn fn, void *context, struct dpages *dp, io_notify_fn fn, void *context,
unsigned short ioprio) unsigned short ioprio)
{ {
struct io *io; struct io *io;
if (num_regions > 1 && !op_is_write(opf)) {
WARN_ON(1);
fn(1, context);
return -EIO;
}
io = mempool_alloc(&client->pool, GFP_NOIO); io = mempool_alloc(&client->pool, GFP_NOIO);
io->error_bits = 0; io->error_bits = 0;
atomic_set(&io->count, 1); /* see dispatch_io() */ atomic_set(&io->count, 1); /* see dispatch_io() */
...@@ -482,7 +471,6 @@ static int async_io(struct dm_io_client *client, unsigned int num_regions, ...@@ -482,7 +471,6 @@ static int async_io(struct dm_io_client *client, unsigned int num_regions,
io->vma_invalidate_size = dp->vma_invalidate_size; 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, 0, ioprio);
return 0;
} }
static int dp_init(struct dm_io_request *io_req, struct dpages *dp, static int dp_init(struct dm_io_request *io_req, struct dpages *dp,
...@@ -529,6 +517,11 @@ int dm_io(struct dm_io_request *io_req, unsigned int num_regions, ...@@ -529,6 +517,11 @@ int dm_io(struct dm_io_request *io_req, unsigned int num_regions,
int r; int r;
struct dpages dp; struct dpages dp;
if (num_regions > 1 && !op_is_write(io_req->bi_opf)) {
WARN_ON(1);
return -EIO;
}
r = dp_init(io_req, &dp, (unsigned long)where->count << SECTOR_SHIFT); r = dp_init(io_req, &dp, (unsigned long)where->count << SECTOR_SHIFT);
if (r) if (r)
return r; return r;
...@@ -537,9 +530,9 @@ int dm_io(struct dm_io_request *io_req, unsigned int num_regions, ...@@ -537,9 +530,9 @@ int dm_io(struct dm_io_request *io_req, unsigned int num_regions,
return sync_io(io_req->client, num_regions, where, return sync_io(io_req->client, num_regions, where,
io_req->bi_opf, &dp, sync_error_bits, ioprio); io_req->bi_opf, &dp, sync_error_bits, ioprio);
return async_io(io_req->client, num_regions, where, async_io(io_req->client, num_regions, where, io_req->bi_opf, &dp,
io_req->bi_opf, &dp, io_req->notify.fn, io_req->notify.fn, io_req->notify.context, ioprio);
io_req->notify.context, ioprio); return 0;
} }
EXPORT_SYMBOL(dm_io); EXPORT_SYMBOL(dm_io);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment