Commit 6a1b1ddc authored by Mike Snitzer's avatar Mike Snitzer

dm thin metadata: add wrappers for managing write locking of metadata

No functional change, but this prepares to hook off of pmd_write_lock()
with additional functionality (as provided in next commit).
Suggested-by: default avatarJoe Thornber <ejt@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent a1ed4d9e
...@@ -367,6 +367,26 @@ static int subtree_equal(void *context, const void *value1_le, const void *value ...@@ -367,6 +367,26 @@ static int subtree_equal(void *context, const void *value1_le, const void *value
/*----------------------------------------------------------------*/ /*----------------------------------------------------------------*/
static inline void __pmd_write_lock(struct dm_pool_metadata *pmd)
__acquires(pmd->root_lock)
{
down_write(&pmd->root_lock);
}
#define pmd_write_lock_in_core(pmd) __pmd_write_lock((pmd))
static inline void pmd_write_lock(struct dm_pool_metadata *pmd)
{
__pmd_write_lock(pmd);
}
static inline void pmd_write_unlock(struct dm_pool_metadata *pmd)
__releases(pmd->root_lock)
{
up_write(&pmd->root_lock);
}
/*----------------------------------------------------------------*/
static int superblock_lock_zero(struct dm_pool_metadata *pmd, static int superblock_lock_zero(struct dm_pool_metadata *pmd,
struct dm_block **sblock) struct dm_block **sblock)
{ {
...@@ -1032,10 +1052,10 @@ int dm_pool_create_thin(struct dm_pool_metadata *pmd, dm_thin_id dev) ...@@ -1032,10 +1052,10 @@ int dm_pool_create_thin(struct dm_pool_metadata *pmd, dm_thin_id dev)
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&pmd->root_lock); pmd_write_lock(pmd);
if (!pmd->fail_io) if (!pmd->fail_io)
r = __create_thin(pmd, dev); r = __create_thin(pmd, dev);
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
...@@ -1123,10 +1143,10 @@ int dm_pool_create_snap(struct dm_pool_metadata *pmd, ...@@ -1123,10 +1143,10 @@ int dm_pool_create_snap(struct dm_pool_metadata *pmd,
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&pmd->root_lock); pmd_write_lock(pmd);
if (!pmd->fail_io) if (!pmd->fail_io)
r = __create_snap(pmd, dev, origin); r = __create_snap(pmd, dev, origin);
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
...@@ -1166,10 +1186,10 @@ int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd, ...@@ -1166,10 +1186,10 @@ int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd,
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&pmd->root_lock); pmd_write_lock(pmd);
if (!pmd->fail_io) if (!pmd->fail_io)
r = __delete_device(pmd, dev); r = __delete_device(pmd, dev);
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
...@@ -1180,7 +1200,7 @@ int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd, ...@@ -1180,7 +1200,7 @@ int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd,
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&pmd->root_lock); pmd_write_lock(pmd);
if (pmd->fail_io) if (pmd->fail_io)
goto out; goto out;
...@@ -1194,7 +1214,7 @@ int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd, ...@@ -1194,7 +1214,7 @@ int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd,
r = 0; r = 0;
out: out:
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
...@@ -1288,10 +1308,10 @@ int dm_pool_reserve_metadata_snap(struct dm_pool_metadata *pmd) ...@@ -1288,10 +1308,10 @@ int dm_pool_reserve_metadata_snap(struct dm_pool_metadata *pmd)
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&pmd->root_lock); pmd_write_lock(pmd);
if (!pmd->fail_io) if (!pmd->fail_io)
r = __reserve_metadata_snap(pmd); r = __reserve_metadata_snap(pmd);
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
...@@ -1336,10 +1356,10 @@ int dm_pool_release_metadata_snap(struct dm_pool_metadata *pmd) ...@@ -1336,10 +1356,10 @@ int dm_pool_release_metadata_snap(struct dm_pool_metadata *pmd)
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&pmd->root_lock); pmd_write_lock(pmd);
if (!pmd->fail_io) if (!pmd->fail_io)
r = __release_metadata_snap(pmd); r = __release_metadata_snap(pmd);
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
...@@ -1382,19 +1402,19 @@ int dm_pool_open_thin_device(struct dm_pool_metadata *pmd, dm_thin_id dev, ...@@ -1382,19 +1402,19 @@ int dm_pool_open_thin_device(struct dm_pool_metadata *pmd, dm_thin_id dev,
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&pmd->root_lock); pmd_write_lock_in_core(pmd);
if (!pmd->fail_io) if (!pmd->fail_io)
r = __open_device(pmd, dev, 0, td); r = __open_device(pmd, dev, 0, td);
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
int dm_pool_close_thin_device(struct dm_thin_device *td) int dm_pool_close_thin_device(struct dm_thin_device *td)
{ {
down_write(&td->pmd->root_lock); pmd_write_lock_in_core(td->pmd);
__close_device(td); __close_device(td);
up_write(&td->pmd->root_lock); pmd_write_unlock(td->pmd);
return 0; return 0;
} }
...@@ -1575,10 +1595,10 @@ int dm_thin_insert_block(struct dm_thin_device *td, dm_block_t block, ...@@ -1575,10 +1595,10 @@ int dm_thin_insert_block(struct dm_thin_device *td, dm_block_t block,
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&td->pmd->root_lock); pmd_write_lock(td->pmd);
if (!td->pmd->fail_io) if (!td->pmd->fail_io)
r = __insert(td, block, data_block); r = __insert(td, block, data_block);
up_write(&td->pmd->root_lock); pmd_write_unlock(td->pmd);
return r; return r;
} }
...@@ -1662,10 +1682,10 @@ int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block) ...@@ -1662,10 +1682,10 @@ int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block)
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&td->pmd->root_lock); pmd_write_lock(td->pmd);
if (!td->pmd->fail_io) if (!td->pmd->fail_io)
r = __remove(td, block); r = __remove(td, block);
up_write(&td->pmd->root_lock); pmd_write_unlock(td->pmd);
return r; return r;
} }
...@@ -1675,10 +1695,10 @@ int dm_thin_remove_range(struct dm_thin_device *td, ...@@ -1675,10 +1695,10 @@ int dm_thin_remove_range(struct dm_thin_device *td,
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&td->pmd->root_lock); pmd_write_lock(td->pmd);
if (!td->pmd->fail_io) if (!td->pmd->fail_io)
r = __remove_range(td, begin, end); r = __remove_range(td, begin, end);
up_write(&td->pmd->root_lock); pmd_write_unlock(td->pmd);
return r; return r;
} }
...@@ -1701,13 +1721,13 @@ int dm_pool_inc_data_range(struct dm_pool_metadata *pmd, dm_block_t b, dm_block_ ...@@ -1701,13 +1721,13 @@ int dm_pool_inc_data_range(struct dm_pool_metadata *pmd, dm_block_t b, dm_block_
{ {
int r = 0; int r = 0;
down_write(&pmd->root_lock); pmd_write_lock(pmd);
for (; b != e; b++) { for (; b != e; b++) {
r = dm_sm_inc_block(pmd->data_sm, b); r = dm_sm_inc_block(pmd->data_sm, b);
if (r) if (r)
break; break;
} }
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
...@@ -1716,13 +1736,13 @@ int dm_pool_dec_data_range(struct dm_pool_metadata *pmd, dm_block_t b, dm_block_ ...@@ -1716,13 +1736,13 @@ int dm_pool_dec_data_range(struct dm_pool_metadata *pmd, dm_block_t b, dm_block_
{ {
int r = 0; int r = 0;
down_write(&pmd->root_lock); pmd_write_lock(pmd);
for (; b != e; b++) { for (; b != e; b++) {
r = dm_sm_dec_block(pmd->data_sm, b); r = dm_sm_dec_block(pmd->data_sm, b);
if (r) if (r)
break; break;
} }
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
...@@ -1770,10 +1790,10 @@ int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result) ...@@ -1770,10 +1790,10 @@ int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result)
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&pmd->root_lock); pmd_write_lock(pmd);
if (!pmd->fail_io) if (!pmd->fail_io)
r = dm_sm_new_block(pmd->data_sm, result); r = dm_sm_new_block(pmd->data_sm, result);
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
...@@ -1782,7 +1802,7 @@ int dm_pool_commit_metadata(struct dm_pool_metadata *pmd) ...@@ -1782,7 +1802,7 @@ int dm_pool_commit_metadata(struct dm_pool_metadata *pmd)
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&pmd->root_lock); pmd_write_lock(pmd);
if (pmd->fail_io) if (pmd->fail_io)
goto out; goto out;
...@@ -1795,7 +1815,7 @@ int dm_pool_commit_metadata(struct dm_pool_metadata *pmd) ...@@ -1795,7 +1815,7 @@ int dm_pool_commit_metadata(struct dm_pool_metadata *pmd)
*/ */
r = __begin_transaction(pmd); r = __begin_transaction(pmd);
out: out:
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
...@@ -1811,7 +1831,7 @@ int dm_pool_abort_metadata(struct dm_pool_metadata *pmd) ...@@ -1811,7 +1831,7 @@ int dm_pool_abort_metadata(struct dm_pool_metadata *pmd)
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&pmd->root_lock); pmd_write_lock(pmd);
if (pmd->fail_io) if (pmd->fail_io)
goto out; goto out;
...@@ -1822,7 +1842,7 @@ int dm_pool_abort_metadata(struct dm_pool_metadata *pmd) ...@@ -1822,7 +1842,7 @@ int dm_pool_abort_metadata(struct dm_pool_metadata *pmd)
pmd->fail_io = true; pmd->fail_io = true;
out: out:
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
...@@ -1953,10 +1973,10 @@ int dm_pool_resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_count) ...@@ -1953,10 +1973,10 @@ int dm_pool_resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_count)
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&pmd->root_lock); pmd_write_lock(pmd);
if (!pmd->fail_io) if (!pmd->fail_io)
r = __resize_space_map(pmd->data_sm, new_count); r = __resize_space_map(pmd->data_sm, new_count);
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
...@@ -1965,29 +1985,29 @@ int dm_pool_resize_metadata_dev(struct dm_pool_metadata *pmd, dm_block_t new_cou ...@@ -1965,29 +1985,29 @@ int dm_pool_resize_metadata_dev(struct dm_pool_metadata *pmd, dm_block_t new_cou
{ {
int r = -EINVAL; int r = -EINVAL;
down_write(&pmd->root_lock); pmd_write_lock(pmd);
if (!pmd->fail_io) { if (!pmd->fail_io) {
r = __resize_space_map(pmd->metadata_sm, new_count); r = __resize_space_map(pmd->metadata_sm, new_count);
if (!r) if (!r)
__set_metadata_reserve(pmd); __set_metadata_reserve(pmd);
} }
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
void dm_pool_metadata_read_only(struct dm_pool_metadata *pmd) void dm_pool_metadata_read_only(struct dm_pool_metadata *pmd)
{ {
down_write(&pmd->root_lock); pmd_write_lock_in_core(pmd);
dm_bm_set_read_only(pmd->bm); dm_bm_set_read_only(pmd->bm);
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
} }
void dm_pool_metadata_read_write(struct dm_pool_metadata *pmd) void dm_pool_metadata_read_write(struct dm_pool_metadata *pmd)
{ {
down_write(&pmd->root_lock); pmd_write_lock_in_core(pmd);
dm_bm_set_read_write(pmd->bm); dm_bm_set_read_write(pmd->bm);
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
} }
int dm_pool_register_metadata_threshold(struct dm_pool_metadata *pmd, int dm_pool_register_metadata_threshold(struct dm_pool_metadata *pmd,
...@@ -1997,9 +2017,9 @@ int dm_pool_register_metadata_threshold(struct dm_pool_metadata *pmd, ...@@ -1997,9 +2017,9 @@ int dm_pool_register_metadata_threshold(struct dm_pool_metadata *pmd,
{ {
int r; int r;
down_write(&pmd->root_lock); pmd_write_lock_in_core(pmd);
r = dm_sm_register_threshold_callback(pmd->metadata_sm, threshold, fn, context); r = dm_sm_register_threshold_callback(pmd->metadata_sm, threshold, fn, context);
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
...@@ -2010,7 +2030,7 @@ int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd) ...@@ -2010,7 +2030,7 @@ int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd)
struct dm_block *sblock; struct dm_block *sblock;
struct thin_disk_superblock *disk_super; struct thin_disk_superblock *disk_super;
down_write(&pmd->root_lock); pmd_write_lock(pmd);
pmd->flags |= THIN_METADATA_NEEDS_CHECK_FLAG; pmd->flags |= THIN_METADATA_NEEDS_CHECK_FLAG;
r = superblock_lock(pmd, &sblock); r = superblock_lock(pmd, &sblock);
...@@ -2024,7 +2044,7 @@ int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd) ...@@ -2024,7 +2044,7 @@ int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd)
dm_bm_unlock(sblock); dm_bm_unlock(sblock);
out: out:
up_write(&pmd->root_lock); pmd_write_unlock(pmd);
return r; return r;
} }
......
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