提交 25971192 编写于 作者: J Joe Thornber 提交者: Alasdair G Kergon

dm thin metadata: wrap superblock locking

Introduce wrappers to handle write locking the superblock
appropriately.
Signed-off-by: NJoe Thornber <ejt@redhat.com>
Signed-off-by: NMike Snitzer <snitzer@redhat.com>
Signed-off-by: NAlasdair G Kergon <agk@redhat.com>
上级 3c9ad9bd
...@@ -343,6 +343,20 @@ static int subtree_equal(void *context, void *value1_le, void *value2_le) ...@@ -343,6 +343,20 @@ static int subtree_equal(void *context, void *value1_le, void *value2_le)
/*----------------------------------------------------------------*/ /*----------------------------------------------------------------*/
static int superblock_lock_zero(struct dm_pool_metadata *pmd,
struct dm_block **sblock)
{
return dm_bm_write_lock_zero(pmd->bm, THIN_SUPERBLOCK_LOCATION,
&sb_validator, sblock);
}
static int superblock_lock(struct dm_pool_metadata *pmd,
struct dm_block **sblock)
{
return dm_bm_write_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION,
&sb_validator, sblock);
}
static int superblock_all_zeroes(struct dm_block_manager *bm, int *result) static int superblock_all_zeroes(struct dm_block_manager *bm, int *result)
{ {
int r; int r;
...@@ -430,22 +444,11 @@ static int init_pmd(struct dm_pool_metadata *pmd, ...@@ -430,22 +444,11 @@ static int init_pmd(struct dm_pool_metadata *pmd,
r = PTR_ERR(data_sm); r = PTR_ERR(data_sm);
goto bad; goto bad;
} }
/*
* We cycle the superblock to let the validator do its stuff.
*/
r = dm_bm_write_lock_zero(bm, THIN_SUPERBLOCK_LOCATION, &sb_validator, &sblock);
if (r < 0) {
DMERR("couldn't lock superblock");
goto bad;
}
dm_bm_unlock(sblock);
} else { } else {
struct thin_disk_superblock *disk_super; struct thin_disk_superblock *disk_super;
r = dm_bm_read_lock(bm, THIN_SUPERBLOCK_LOCATION, &sb_validator, &sblock); r = dm_bm_read_lock(bm, THIN_SUPERBLOCK_LOCATION,
&sb_validator, &sblock);
if (r < 0) { if (r < 0) {
DMERR("couldn't read superblock"); DMERR("couldn't read superblock");
return r; return r;
...@@ -628,8 +631,7 @@ static int __commit_transaction(struct dm_pool_metadata *pmd) ...@@ -628,8 +631,7 @@ static int __commit_transaction(struct dm_pool_metadata *pmd)
if (r < 0) if (r < 0)
return r; return r;
r = dm_bm_write_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION, r = superblock_lock(pmd, &sblock);
&sb_validator, &sblock);
if (r) if (r)
return r; return r;
...@@ -709,8 +711,7 @@ struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev, ...@@ -709,8 +711,7 @@ struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
/* /*
* Create. * Create.
*/ */
r = dm_bm_write_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION, r = superblock_lock_zero(pmd, &sblock);
&sb_validator, &sblock);
if (r) if (r)
goto bad; goto bad;
...@@ -1126,8 +1127,7 @@ static int __reserve_metadata_snap(struct dm_pool_metadata *pmd) ...@@ -1126,8 +1127,7 @@ static int __reserve_metadata_snap(struct dm_pool_metadata *pmd)
/* /*
* Write the held root into the superblock. * Write the held root into the superblock.
*/ */
r = dm_bm_write_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION, r = superblock_lock(pmd, &sblock);
&sb_validator, &sblock);
if (r) { if (r) {
dm_tm_dec(pmd->tm, held_root); dm_tm_dec(pmd->tm, held_root);
return r; return r;
...@@ -1157,8 +1157,7 @@ static int __release_metadata_snap(struct dm_pool_metadata *pmd) ...@@ -1157,8 +1157,7 @@ static int __release_metadata_snap(struct dm_pool_metadata *pmd)
struct dm_block *sblock, *copy; struct dm_block *sblock, *copy;
dm_block_t held_root; dm_block_t held_root;
r = dm_bm_write_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION, r = superblock_lock(pmd, &sblock);
&sb_validator, &sblock);
if (r) if (r)
return r; return r;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册