dm thin metadata: move dm_commit_pool_metadata into __write_initial_superblock
authorJoe Thornber <ejt@redhat.com>
Fri, 27 Jul 2012 14:08:11 +0000 (15:08 +0100)
committerAlasdair G Kergon <agk@redhat.com>
Fri, 27 Jul 2012 14:08:11 +0000 (15:08 +0100)
Move dm_commit_pool_metadata inline into __write_initial_superblock 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>
drivers/md/dm-thin-metadata.c

index 5ead655706d490d249c62dd29a55b9e1d89feaf4..2c44c5c10987c1a2861fc9b1f5cef2cbe0f56299 100644 (file)
@@ -422,38 +422,70 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
        pmd->details_info.value_type.equal = NULL;
 }
 
+static int __begin_transaction(struct dm_pool_metadata *pmd);
 static int __write_initial_superblock(struct dm_pool_metadata *pmd)
 {
        int r;
        struct dm_block *sblock;
+       size_t metadata_len, data_len;
        struct thin_disk_superblock *disk_super;
        sector_t bdev_size = i_size_read(pmd->bdev->bd_inode) >> SECTOR_SHIFT;
 
        if (bdev_size > THIN_METADATA_MAX_SECTORS)
                bdev_size = THIN_METADATA_MAX_SECTORS;
 
+       r = dm_sm_root_size(pmd->metadata_sm, &metadata_len);
+       if (r < 0)
+               return r;
+
+       r = dm_sm_root_size(pmd->data_sm, &data_len);
+       if (r < 0)
+               return r;
+
+       r = dm_sm_commit(pmd->data_sm);
+       if (r < 0)
+               return r;
+
+       r = dm_tm_pre_commit(pmd->tm);
+       if (r < 0)
+               return r;
+
        r = superblock_lock_zero(pmd, &sblock);
        if (r)
                return r;
 
        disk_super = dm_block_data(sblock);
+       disk_super->flags = 0;
        disk_super->magic = cpu_to_le64(THIN_SUPERBLOCK_MAGIC);
        disk_super->version = cpu_to_le32(THIN_VERSION);
        disk_super->time = 0;
+       disk_super->trans_id = 0;
+       disk_super->held_root = 0;
+
+       r = dm_sm_copy_root(pmd->metadata_sm, &disk_super->metadata_space_map_root,
+                           metadata_len);
+       if (r < 0)
+               goto bad_locked;
+
+       r = dm_sm_copy_root(pmd->data_sm, &disk_super->data_space_map_root,
+                           data_len);
+       if (r < 0)
+               goto bad_locked;
+
+       disk_super->data_mapping_root = cpu_to_le64(pmd->root);
+       disk_super->device_details_root = cpu_to_le64(pmd->details_root);
        disk_super->metadata_block_size = cpu_to_le32(THIN_METADATA_BLOCK_SIZE >> SECTOR_SHIFT);
        disk_super->metadata_nr_blocks = cpu_to_le64(bdev_size >> SECTOR_TO_BLOCK_SHIFT);
        disk_super->data_block_size = cpu_to_le32(pmd->data_block_size);
 
-       r = dm_bm_unlock(sblock);
+       r = dm_tm_commit(pmd->tm, sblock);
        if (r)
                return r;
 
-       pmd->flags = 0;
-       r = dm_pool_commit_metadata(pmd);
-       if (r < 0)
-               DMERR("%s: dm_pool_commit_metadata() failed, error = %d",
-                     __func__, r);
+       return __begin_transaction(pmd);
 
+bad_locked:
+       dm_bm_unlock(sblock);
        return r;
 }