Commit e5cfc69a authored by Joe Thornber's avatar Joe Thornber Committed by Mike Snitzer

dm thin metadata: change dm_thin_find_block to allow blocking, but not issuing, IO

This change is a prerequisite for allowing metadata to be prefetched.
Signed-off-by: default avatarJoe Thornber <ejt@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent a195db2d
...@@ -1384,42 +1384,38 @@ static bool __snapshotted_since(struct dm_thin_device *td, uint32_t time) ...@@ -1384,42 +1384,38 @@ static bool __snapshotted_since(struct dm_thin_device *td, uint32_t time)
} }
int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block, int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
int can_block, struct dm_thin_lookup_result *result) int can_issue_io, struct dm_thin_lookup_result *result)
{ {
int r = -EINVAL; int r;
uint64_t block_time = 0;
__le64 value; __le64 value;
struct dm_pool_metadata *pmd = td->pmd; struct dm_pool_metadata *pmd = td->pmd;
dm_block_t keys[2] = { td->id, block }; dm_block_t keys[2] = { td->id, block };
struct dm_btree_info *info; struct dm_btree_info *info;
if (can_block) { if (pmd->fail_io)
return -EINVAL;
down_read(&pmd->root_lock); down_read(&pmd->root_lock);
if (can_issue_io) {
info = &pmd->info; info = &pmd->info;
} else if (down_read_trylock(&pmd->root_lock)) } else
info = &pmd->nb_info; info = &pmd->nb_info;
else
return -EWOULDBLOCK;
if (pmd->fail_io)
goto out;
r = dm_btree_lookup(info, pmd->root, keys, &value); r = dm_btree_lookup(info, pmd->root, keys, &value);
if (!r)
block_time = le64_to_cpu(value);
out:
up_read(&pmd->root_lock);
if (!r) { if (!r) {
uint64_t block_time = 0;
dm_block_t exception_block; dm_block_t exception_block;
uint32_t exception_time; uint32_t exception_time;
block_time = le64_to_cpu(value);
unpack_block_time(block_time, &exception_block, unpack_block_time(block_time, &exception_block,
&exception_time); &exception_time);
result->block = exception_block; result->block = exception_block;
result->shared = __snapshotted_since(td, exception_time); result->shared = __snapshotted_since(td, exception_time);
} }
up_read(&pmd->root_lock);
return r; return r;
} }
......
...@@ -139,12 +139,12 @@ struct dm_thin_lookup_result { ...@@ -139,12 +139,12 @@ struct dm_thin_lookup_result {
/* /*
* Returns: * Returns:
* -EWOULDBLOCK iff @can_block is set and would block. * -EWOULDBLOCK iff @can_issue_io is set and would issue IO
* -ENODATA iff that mapping is not present. * -ENODATA iff that mapping is not present.
* 0 success * 0 success
*/ */
int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block, int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
int can_block, struct dm_thin_lookup_result *result); int can_issue_io, struct dm_thin_lookup_result *result);
/* /*
* Obtain an unused block. * Obtain an unused block.
......
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