dm thin metadata: split __open or format metadata

Split __open_or_format_metadata into __format_metadata and __open_metadata in
dm-thin-metadata.

Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
This commit is contained in:
Joe Thornber 2012-07-27 15:08:12 +01:00 committed by Alasdair G Kergon
parent d6332814e3
commit e4d2205cdf
1 changed files with 74 additions and 50 deletions

View File

@ -485,13 +485,10 @@ bad_locked:
return r;
}
static int __open_or_format_metadata(struct dm_pool_metadata *pmd,
dm_block_t nr_blocks, int create)
static int __format_metadata(struct dm_pool_metadata *pmd, dm_block_t nr_blocks)
{
int r;
struct dm_block *sblock;
if (create) {
r = dm_tm_create_with_sm(pmd->bm, THIN_SUPERBLOCK_LOCATION,
&pmd->tm, &pmd->metadata_sm);
if (r < 0) {
@ -505,7 +502,50 @@ static int __open_or_format_metadata(struct dm_pool_metadata *pmd,
r = PTR_ERR(pmd->data_sm);
goto bad;
}
} else {
pmd->nb_tm = dm_tm_create_non_blocking_clone(pmd->tm);
if (!pmd->nb_tm) {
DMERR("could not create clone tm");
r = -ENOMEM;
goto bad_data_sm;
}
__setup_btree_details(pmd);
pmd->root = 0;
pmd->details_root = 0;
pmd->trans_id = 0;
pmd->flags = 0;
r = dm_btree_empty(&pmd->info, &pmd->root);
if (r < 0)
goto bad_data_sm;
r = dm_btree_empty(&pmd->details_info, &pmd->details_root);
if (r < 0) {
DMERR("couldn't create devices root");
goto bad_data_sm;
}
r = __write_initial_superblock(pmd);
if (r)
goto bad_data_sm;
return 0;
bad_data_sm:
dm_sm_destroy(pmd->data_sm);
bad:
dm_tm_destroy(pmd->tm);
dm_sm_destroy(pmd->metadata_sm);
return r;
}
static int __open_metadata(struct dm_pool_metadata *pmd)
{
int r;
struct dm_block *sblock;
struct thin_disk_superblock *disk_super;
r = dm_bm_read_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION,
@ -536,7 +576,6 @@ static int __open_or_format_metadata(struct dm_pool_metadata *pmd,
}
dm_bm_unlock(sblock);
}
pmd->nb_tm = dm_tm_create_non_blocking_clone(pmd->tm);
if (!pmd->nb_tm) {
@ -547,30 +586,6 @@ static int __open_or_format_metadata(struct dm_pool_metadata *pmd,
__setup_btree_details(pmd);
pmd->root = 0;
pmd->details_root = 0;
pmd->trans_id = 0;
pmd->flags = 0;
if (!create)
return 0;
r = dm_btree_empty(&pmd->info, &pmd->root);
if (r < 0)
goto bad_data_sm;
r = dm_btree_empty(&pmd->details_info, &pmd->details_root);
if (r < 0) {
DMERR("couldn't create devices root");
goto bad_data_sm;
}
r = __write_initial_superblock(pmd);
if (r)
goto bad_data_sm;
return 0;
bad_data_sm:
dm_sm_destroy(pmd->data_sm);
bad:
@ -580,6 +595,15 @@ bad:
return r;
}
static int __open_or_format_metadata(struct dm_pool_metadata *pmd,
dm_block_t nr_blocks, int create)
{
if (create)
return __format_metadata(pmd, nr_blocks);
else
return __open_metadata(pmd);
}
static int __create_persistent_data_objects(struct dm_pool_metadata *pmd,
dm_block_t nr_blocks, int *create)
{