linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>
Subject: [PATCH 06/13] btrfs-progs: mkfs: return errors from block group creation functions
Date: Tue, 23 Aug 2016 12:25:10 +0200	[thread overview]
Message-ID: <1471947917-5324-7-git-send-email-dsterba@suse.com> (raw)
In-Reply-To: <1471947917-5324-1-git-send-email-dsterba@suse.com>

No more BUG_ONs, we don't care about cleanup as the filesystem is
supposed to be marked as partial.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 mkfs.c | 75 ++++++++++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 48 insertions(+), 27 deletions(-)

diff --git a/mkfs.c b/mkfs.c
index ee5a30daff54..b2baf47bb595 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -79,7 +79,8 @@ static int create_metadata_block_groups(struct btrfs_root *root, int mixed,
 				     BTRFS_FIRST_CHUNK_TREE_OBJECTID,
 				     0, BTRFS_MKFS_SYSTEM_GROUP_SIZE);
 	allocation->system += BTRFS_MKFS_SYSTEM_GROUP_SIZE;
-	BUG_ON(ret);
+	if (ret)
+		return ret;
 
 	if (mixed) {
 		ret = btrfs_alloc_chunk(trans, root->fs_info->extent_root,
@@ -90,13 +91,15 @@ static int create_metadata_block_groups(struct btrfs_root *root, int mixed,
 			error("no space to allocate data/metadata chunk");
 			goto err;
 		}
-		BUG_ON(ret);
+		if (ret)
+			return ret;
 		ret = btrfs_make_block_group(trans, root, 0,
 					     BTRFS_BLOCK_GROUP_METADATA |
 					     BTRFS_BLOCK_GROUP_DATA,
 					     BTRFS_FIRST_CHUNK_TREE_OBJECTID,
 					     chunk_start, chunk_size);
-		BUG_ON(ret);
+		if (ret)
+			return ret;
 		allocation->mixed += chunk_size;
 	} else {
 		ret = btrfs_alloc_chunk(trans, root->fs_info->extent_root,
@@ -106,17 +109,19 @@ static int create_metadata_block_groups(struct btrfs_root *root, int mixed,
 			error("no space to allocate metadata chunk");
 			goto err;
 		}
-		BUG_ON(ret);
+		if (ret)
+			return ret;
 		ret = btrfs_make_block_group(trans, root, 0,
 					     BTRFS_BLOCK_GROUP_METADATA,
 					     BTRFS_FIRST_CHUNK_TREE_OBJECTID,
 					     chunk_start, chunk_size);
 		allocation->metadata += chunk_size;
-		BUG_ON(ret);
+		if (ret)
+			return ret;
 	}
 
 	root->fs_info->system_allocs = 0;
-	btrfs_commit_transaction(trans, root);
+	ret = btrfs_commit_transaction(trans, root);
 
 err:
 	return ret;
@@ -138,13 +143,15 @@ static int create_data_block_groups(struct btrfs_trans_handle *trans,
 			error("no space to allocate data chunk");
 			goto err;
 		}
-		BUG_ON(ret);
+		if (ret)
+			return ret;
 		ret = btrfs_make_block_group(trans, root, 0,
 					     BTRFS_BLOCK_GROUP_DATA,
 					     BTRFS_FIRST_CHUNK_TREE_OBJECTID,
 					     chunk_start, chunk_size);
 		allocation->data += chunk_size;
-		BUG_ON(ret);
+		if (ret)
+			return ret;
 	}
 
 err:
@@ -226,23 +233,29 @@ static int create_one_raid_group(struct btrfs_trans_handle *trans,
 		error("not enough free space to allocate chunk");
 		exit(1);
 	}
-	BUG_ON(ret);
+	if (ret)
+		return ret;
+
 	ret = btrfs_make_block_group(trans, root->fs_info->extent_root, 0,
 				     type, BTRFS_FIRST_CHUNK_TREE_OBJECTID,
 				     chunk_start, chunk_size);
-	if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == BTRFS_BLOCK_GROUP_DATA)
+
+	type &= BTRFS_BLOCK_GROUP_TYPE_MASK;
+	if (type == BTRFS_BLOCK_GROUP_DATA) {
 		allocation->data += chunk_size;
-	else if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == BTRFS_BLOCK_GROUP_METADATA)
+	} else if (type == BTRFS_BLOCK_GROUP_METADATA) {
 		allocation->metadata += chunk_size;
-	else if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == BTRFS_BLOCK_GROUP_SYSTEM)
+	} else if (type == BTRFS_BLOCK_GROUP_SYSTEM) {
 		allocation->system += chunk_size;
-	else if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) ==
-			(BTRFS_BLOCK_GROUP_METADATA|BTRFS_BLOCK_GROUP_DATA))
+	} else if (type ==
+			(BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA)) {
 		allocation->mixed += chunk_size;
-	else
-		BUG_ON(1);
+	} else {
+		error("unrecognized profile type: 0x%llx",
+				(unsigned long long)type);
+		ret = -EINVAL;
+	}
 
-	BUG_ON(ret);
 	return ret;
 }
 
@@ -259,21 +272,24 @@ static int create_raid_groups(struct btrfs_trans_handle *trans,
 		ret = create_one_raid_group(trans, root,
 					    BTRFS_BLOCK_GROUP_SYSTEM |
 					    metadata_profile, allocation);
-		BUG_ON(ret);
+		if (ret)
+			return ret;
 
 		if (mixed)
 			meta_flags |= BTRFS_BLOCK_GROUP_DATA;
 
 		ret = create_one_raid_group(trans, root, meta_flags |
 					    metadata_profile, allocation);
-		BUG_ON(ret);
+		if (ret)
+			return ret;
 
 	}
 	if (!mixed && data_profile) {
 		ret = create_one_raid_group(trans, root,
 					    BTRFS_BLOCK_GROUP_DATA |
 					    data_profile, allocation);
-		BUG_ON(ret);
+		if (ret)
+			return ret;
 	}
 	recow_roots(trans, root);
 
@@ -290,7 +306,8 @@ static int create_data_reloc_tree(struct btrfs_trans_handle *trans,
 	int ret;
 
 	ret = btrfs_copy_root(trans, root, root->node, &tmp, objectid);
-	BUG_ON(ret);
+	if (ret)
+		return ret;
 
 	memcpy(&root_item, &root->root_item, sizeof(root_item));
 	btrfs_set_root_bytenr(&root_item, tmp->start);
@@ -303,8 +320,8 @@ static int create_data_reloc_tree(struct btrfs_trans_handle *trans,
 	location.offset = 0;
 	ret = btrfs_insert_root(trans, root->fs_info->tree_root,
 				&location, &root_item);
-	BUG_ON(ret);
-	return 0;
+
+	return ret;
 }
 
 static void print_usage(int ret)
@@ -968,12 +985,14 @@ static int create_chunks(struct btrfs_trans_handle *trans,
 	for (i = 0; i < num_of_meta_chunks; i++) {
 		ret = btrfs_alloc_chunk(trans, root->fs_info->extent_root,
 					&chunk_start, &chunk_size, meta_type);
-		BUG_ON(ret);
+		if (ret)
+			return ret;
 		ret = btrfs_make_block_group(trans, root->fs_info->extent_root, 0,
 					     meta_type, BTRFS_FIRST_CHUNK_TREE_OBJECTID,
 					     chunk_start, chunk_size);
 		allocation->metadata += chunk_size;
-		BUG_ON(ret);
+		if (ret)
+			return ret;
 		set_extent_dirty(&root->fs_info->free_space_cache,
 				 chunk_start, chunk_start + chunk_size - 1, 0);
 	}
@@ -983,12 +1002,14 @@ static int create_chunks(struct btrfs_trans_handle *trans,
 
 	ret = btrfs_alloc_data_chunk(trans, root->fs_info->extent_root,
 				     &chunk_start, size_of_data, data_type, 0);
-	BUG_ON(ret);
+	if (ret)
+		return ret;
 	ret = btrfs_make_block_group(trans, root->fs_info->extent_root, 0,
 				     data_type, BTRFS_FIRST_CHUNK_TREE_OBJECTID,
 				     chunk_start, size_of_data);
 	allocation->data += size_of_data;
-	BUG_ON(ret);
+	if (ret)
+		return ret;
 	set_extent_dirty(&root->fs_info->free_space_cache,
 			 chunk_start, chunk_start + size_of_data - 1, 0);
 	return ret;
-- 
2.7.1


  parent reply	other threads:[~2016-08-23 10:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-23 10:25 [PATCH 00/13] Btrfs-progs: partial mkfs/convert, error handling, cleanups David Sterba
2016-08-23 10:25 ` [PATCH 01/13] btrfs-progs: pass OPEN_CTREE flags as unsigned David Sterba
2016-08-24 10:24   ` Anand Jain
2016-08-23 10:25 ` [PATCH 02/13] btrfs-progs: make superblock reading/scanning api more generic David Sterba
2016-08-23 10:25 ` [PATCH 03/13] btrfs-progs: introduce signature for a partially set up filesystem David Sterba
2016-08-23 10:25 ` [PATCH 04/13] btrfs-progs: mkfs: do not scan partially initialized devices David Sterba
2016-08-23 10:25 ` [PATCH 05/13] btrfs-progs: two staged filesystem creation David Sterba
2016-08-24 10:27   ` Anand Jain
2016-08-23 10:25 ` David Sterba [this message]
2016-08-23 10:25 ` [PATCH 07/13] btrfs-progs: mkfs: improve error handling in main() David Sterba
2016-08-23 10:25 ` [PATCH 08/13] btrfs-progs: mkfs: improve error handling in recow_roots David Sterba
2016-08-23 10:25 ` [PATCH 09/13] btrfs-progs: document all btrfs_open_ctree_flags David Sterba
2016-08-23 10:25 ` [PATCH 10/13] btrfs-progs: mkfs: switch BUG_ON to error handling in traverse_directory David Sterba
2016-08-23 10:25 ` [PATCH 11/13] btrfs-progs: mkfs: handle and report transaction commit failures David Sterba
2016-08-23 10:25 ` [PATCH 12/13] btrfs-progs: mkfs: help and usage now to to stdout David Sterba
2016-08-23 10:25 ` [PATCH 13/13] btrfs-progs: mkfs: clean up make_image David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471947917-5324-7-git-send-email-dsterba@suse.com \
    --to=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).