From: Joe Thornber <[email-masked]>

dm thin metadata: integrate that last inline properly

Code tidy.

Signed-off-by: Joe Thornber <[email-masked]>
Signed-off-by: Mike Snitzer <[email-masked]>
---
 drivers/md/dm-thin-metadata.c |   87 ++++++++++++++++--------------------------
 1 file changed, 34 insertions(+), 53 deletions(-)

Index: linux-3.5-rc7/drivers/md/dm-thin-metadata.c
===================================================================
--- linux-3.5-rc7.orig/drivers/md/dm-thin-metadata.c
+++ linux-3.5-rc7/drivers/md/dm-thin-metadata.c
@@ -427,84 +427,65 @@ static int __write_initial_superblock(stru
 {
 	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 out_locked;
+
+	r = dm_sm_copy_root(pmd->data_sm, &disk_super->data_space_map_root,
+			    data_len);
+	if (r < 0)
+		goto out_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;
-
-	{
-		int r;
-		size_t metadata_len, data_len;
-		struct thin_disk_superblock *disk_super;
-		struct dm_block *sblock;
-
-		r = dm_sm_commit(pmd->data_sm);
-		if (r < 0)
-			goto out;
-
-		r = dm_tm_pre_commit(pmd->tm);
-		if (r < 0)
-			goto out;
-
-		r = dm_sm_root_size(pmd->metadata_sm, &metadata_len);
-		if (r < 0)
-			goto out;
-
-		r = dm_sm_root_size(pmd->data_sm, &data_len);
-		if (r < 0)
-			goto out;
-
-		r = superblock_lock(pmd, &sblock);
-		if (r)
-			goto out;
-
-		disk_super = dm_block_data(sblock);
-		disk_super->time = cpu_to_le32(pmd->time);
-		disk_super->data_mapping_root = cpu_to_le64(pmd->root);
-		disk_super->device_details_root = cpu_to_le64(pmd->details_root);
-		disk_super->trans_id = cpu_to_le64(pmd->trans_id);
-		disk_super->flags = cpu_to_le32(pmd->flags);
-
-		r = dm_sm_copy_root(pmd->metadata_sm, &disk_super->metadata_space_map_root,
-				    metadata_len);
-		if (r < 0)
-			goto out_locked;
-
-		r = dm_sm_copy_root(pmd->data_sm, &disk_super->data_space_map_root,
-				    data_len);
-		if (r < 0)
-			goto out_locked;
-
-		r = dm_tm_commit(pmd->tm, sblock);
-		if (r)
-			return r;
-
-	}
-
 	return __begin_transaction(pmd);
 
 out_locked:
 	dm_bm_unlock(sblock);
-out:
 	return r;
 }