]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Move block manager creation and the check for unformatted metadata into
authorJoe Thornber <ejt@redhat.com>
Tue, 24 Jul 2012 23:25:24 +0000 (09:25 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 24 Jul 2012 23:25:24 +0000 (09:25 +1000)
__create_persistent_data_objects().

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>
drivers/md/dm-thin-metadata.c

index 0ef10f70565e2dc863a21060faec5856e5d15fe2..dab2109ec40a23ff08ffb129fead02812d745fd9 100644 (file)
@@ -357,7 +357,7 @@ static int superblock_lock(struct dm_pool_metadata *pmd,
                                &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;
        unsigned i;
@@ -422,9 +422,9 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
        pmd->details_info.value_type.equal = NULL;
 }
 
-static int __create_persistent_data_objects(struct dm_pool_metadata *pmd,
-                                           struct dm_block_manager *bm,
-                                           dm_block_t nr_blocks, int create)
+static int __open_or_format_metadata(struct dm_pool_metadata *pmd,
+                                    struct dm_block_manager *bm,
+                                    dm_block_t nr_blocks, int create)
 {
        int r;
        struct dm_space_map *sm, *data_sm;
@@ -509,6 +509,32 @@ bad:
        return r;
 }
 
+static int __create_persistent_data_objects(struct dm_pool_metadata *pmd,
+                                           dm_block_t nr_blocks, int *create)
+{
+       int r;
+
+       pmd->bm = dm_block_manager_create(pmd->bdev, THIN_METADATA_BLOCK_SIZE,
+                                         THIN_METADATA_CACHE_SIZE,
+                                         THIN_MAX_CONCURRENT_LOCKS);
+       if (IS_ERR(pmd->bm)) {
+               DMERR("could not create block manager");
+               return PTR_ERR(pmd->bm);
+       }
+
+       r = __superblock_all_zeroes(pmd->bm, create);
+       if (r) {
+               dm_block_manager_destroy(pmd->bm);
+               return r;
+       }
+
+       r = __open_or_format_metadata(pmd, pmd->bm, nr_blocks, *create);
+       if (r)
+               dm_block_manager_destroy(pmd->bm);
+
+       return r;
+}
+
 static int __begin_transaction(struct dm_pool_metadata *pmd)
 {
        int r;
@@ -666,7 +692,6 @@ struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
        struct thin_disk_superblock *disk_super;
        struct dm_pool_metadata *pmd;
        sector_t bdev_size = i_size_read(bdev->bd_inode) >> SECTOR_SHIFT;
-       struct dm_block_manager *bm;
        int create;
        struct dm_block *sblock;
 
@@ -676,30 +701,13 @@ struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
                return ERR_PTR(-ENOMEM);
        }
 
-       bm = dm_block_manager_create(bdev, THIN_METADATA_BLOCK_SIZE,
-                                    THIN_METADATA_CACHE_SIZE,
-                                    THIN_MAX_CONCURRENT_LOCKS);
-       if (IS_ERR(bm)) {
-               r = PTR_ERR(bm);
-               DMERR("could not create block manager");
-               kfree(pmd);
-               return ERR_PTR(r);
-       }
-
-       r = superblock_all_zeroes(bm, &create);
-       if (r) {
-               dm_block_manager_destroy(bm);
-               kfree(pmd);
-               return ERR_PTR(r);
-       }
+       pmd->bdev = bdev;
 
-       r = __create_persistent_data_objects(pmd, bm, 0, create);
+       r = __create_persistent_data_objects(pmd, 0, &create);
        if (r) {
-               dm_block_manager_destroy(bm);
                kfree(pmd);
                return ERR_PTR(r);
        }
-       pmd->bdev = bdev;
 
        if (!create) {
                r = __begin_transaction(pmd);