return r;
}
-static int __open_or_format_metadata(struct dm_pool_metadata *pmd)
+static int __open_or_format_metadata(struct dm_pool_metadata *pmd, bool format_device)
{
int r, unformatted;
return r;
if (unformatted)
- return __format_metadata(pmd);
- else
- return __open_metadata(pmd);
+ return format_device ? __format_metadata(pmd) : -EPERM;
+
+ return __open_metadata(pmd);
}
-static int __create_persistent_data_objects(struct dm_pool_metadata *pmd)
+static int __create_persistent_data_objects(struct dm_pool_metadata *pmd, bool format_device)
{
int r;
return PTR_ERR(pmd->bm);
}
- r = __open_or_format_metadata(pmd);
+ r = __open_or_format_metadata(pmd, format_device);
if (r)
dm_block_manager_destroy(pmd->bm);
}
struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
- sector_t data_block_size)
+ sector_t data_block_size,
+ bool format_device)
{
int r;
struct dm_pool_metadata *pmd;
pmd->bdev = bdev;
pmd->data_block_size = data_block_size;
- r = __create_persistent_data_objects(pmd);
+ r = __create_persistent_data_objects(pmd, format_device);
if (r) {
kfree(pmd);
return ERR_PTR(r);
* Reopens or creates a new, empty metadata volume.
*/
struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
- sector_t data_block_size);
+ sector_t data_block_size,
+ bool format_device);
int dm_pool_metadata_close(struct dm_pool_metadata *pmd);
struct pool *pool;
struct dm_pool_metadata *pmd;
- pmd = dm_pool_metadata_open(metadata_dev, block_size);
+ pmd = dm_pool_metadata_open(metadata_dev, block_size, true);
if (IS_ERR(pmd)) {
*error = "Error creating metadata object";
return (struct pool *)pmd;