linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gu Jinxiang <gujx@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 2/2] btrfs-progs: Replace some BUG_ON by return
Date: Wed, 6 Sep 2017 09:42:59 +0800	[thread overview]
Message-ID: <1504662179-21877-2-git-send-email-gujx@cn.fujitsu.com> (raw)
In-Reply-To: <1504662179-21877-1-git-send-email-gujx@cn.fujitsu.com>

The following test failed becasuse there is no data/metadata/system block_group.
Use return ret to replace BUG_ON(ret) to avoid system crash, because there is
enough message for user to understand what happened.

$sudo TEST=003\* make test-fuzz
Unable to find block group for 0
Unable to find block group for 0
Unable to find block group for 0
extent-tree.c:2693: btrfs_reserve_extent: BUG_ON `ret` triggered, value -28
/home/fnst/btrfs/btrfs-progs/btrfs[0x419966]
/home/fnst/btrfs/btrfs-progs/btrfs(btrfs_reserve_extent+0xb16)[0x41f500]
/home/fnst/btrfs/btrfs-progs/btrfs(btrfs_alloc_free_block+0x55)[0x41f59b]
/home/fnst/btrfs/btrfs-progs/btrfs[0x46a6ce]
/home/fnst/btrfs/btrfs-progs/btrfs(cmd_check+0x1012)[0x47c885]
/home/fnst/btrfs/btrfs-progs/btrfs(main+0x127)[0x40b055]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x2aae83e89f45]
/home/fnst/btrfs/btrfs-progs/btrfs[0x40a939]
Creating a new CRC tree
Checking filesystem on /home/fnst/btrfs/btrfs-progs/tests/fuzz-tests/images/bko-155621-bad-block-group-offset.raw.restored
UUID: 5cb33553-6f6d-4ce8-83fd-20af5a2f8181
Reinitialize checksum tree
failed (ignored, ret=134): /home/fnst/btrfs/btrfs-progs/btrfs check --init-csum-tree /home/fnst/btrfs/btrfs-progs/tests/fuzz-tests/images/bko-155621-bad-block-group-offset.raw.restored
mayfail: returned code 134 (SIGABRT), not ignored
test failed for case 003-multi-check-unmounted

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
---
 extent-tree.c | 16 ++++++++++------
 transaction.c |  8 ++++++--
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/extent-tree.c b/extent-tree.c
index eed56886..14838a5d 100644
--- a/extent-tree.c
+++ b/extent-tree.c
@@ -2678,11 +2678,13 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans,
 			ret = do_chunk_alloc(trans, info,
 					     num_bytes,
 					     BTRFS_BLOCK_GROUP_METADATA);
-			BUG_ON(ret);
+			if (ret)
+				goto out;
 		}
 		ret = do_chunk_alloc(trans, info,
 				     num_bytes + SZ_2M, data);
-		BUG_ON(ret);
+		if (ret)
+			goto out;
 	}
 
 	WARN_ON(num_bytes < info->sectorsize);
@@ -2690,9 +2692,11 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans,
 			       search_start, search_end, hint_byte, ins,
 			       trans->alloc_exclude_start,
 			       trans->alloc_exclude_nr, data);
-	BUG_ON(ret);
+	if (ret)
+		goto out;
 	clear_extent_dirty(&info->free_space_cache,
 			   ins->objectid, ins->objectid + ins->offset - 1);
+out:
 	return ret;
 }
 
@@ -2761,7 +2765,8 @@ static int alloc_tree_block(struct btrfs_trans_handle *trans,
 	int ret;
 	ret = btrfs_reserve_extent(trans, root, num_bytes, empty_size,
 				   hint_byte, search_end, ins, 0);
-	BUG_ON(ret);
+	if (ret)
+		goto out;
 
 	if (root_objectid == BTRFS_EXTENT_TREE_OBJECTID) {
 		struct pending_extent_op *extent_op;
@@ -2792,6 +2797,7 @@ static int alloc_tree_block(struct btrfs_trans_handle *trans,
 		finish_current_insert(trans, root->fs_info->extent_root);
 		del_pending_extents(trans, root->fs_info->extent_root);
 	}
+out:
 	return ret;
 }
 
@@ -2813,7 +2819,6 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
 			       trans->transid, 0, key, level,
 			       empty_size, hint, (u64)-1, &ins);
 	if (ret) {
-		BUG_ON(ret > 0);
 		return ERR_PTR(ret);
 	}
 
@@ -2821,7 +2826,6 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
 	if (!buf) {
 		btrfs_free_extent(trans, root, ins.objectid, ins.offset,
 				  0, root->root_key.objectid, level, 0);
-		BUG_ON(1);
 		return ERR_PTR(-ENOMEM);
 	}
 	btrfs_set_buffer_uptodate(buf);
diff --git a/transaction.c b/transaction.c
index ad705728..33225002 100644
--- a/transaction.c
+++ b/transaction.c
@@ -165,9 +165,11 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
 	BUG_ON(ret);
 commit_tree:
 	ret = commit_tree_roots(trans, fs_info);
-	BUG_ON(ret);
+	if (ret)
+		goto error;
 	ret = __commit_transaction(trans, root);
-	BUG_ON(ret);
+	if (ret)
+		goto error;
 	write_ctree_super(trans, fs_info);
 	btrfs_finish_extent_commit(trans, fs_info->extent_root,
 			           &fs_info->pinned_extents);
@@ -177,6 +179,8 @@ commit_tree:
 	fs_info->running_transaction = NULL;
 	fs_info->last_trans_committed = transid;
 	return 0;
+error:
+	return ret;
 }
 
 void btrfs_abort_transaction(struct btrfs_trans_handle *trans, int error)
-- 
2.13.5




  reply	other threads:[~2017-09-06  1:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-06  1:42 [PATCH 1/2] btrfs-progs: Use clean_tree_block when btrfs_update_root fail Gu Jinxiang
2017-09-06  1:42 ` Gu Jinxiang [this message]
2017-11-10 14:11   ` [PATCH 2/2] btrfs-progs: Replace some BUG_ON by return Lakshmipathi.G

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=1504662179-21877-2-git-send-email-gujx@cn.fujitsu.com \
    --to=gujx@cn.fujitsu.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).