* [PATCH] Btrfs: return gracefully from balance if fs tree is corrupted
@ 2016-09-14 15:51 Liu Bo
2016-09-14 17:04 ` Josef Bacik
0 siblings, 1 reply; 2+ messages in thread
From: Liu Bo @ 2016-09-14 15:51 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
When relocating tree blocks, we firstly get block information from
back references in the extent tree, we then search fs tree to try to
find all parents of a block.
However, if fs tree is corrupted, eg. if there're some missing
items, we could come across these WARN_ONs and BUG_ONs.
This makes us print some error messages and return gracefully
from balance.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/relocation.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index c0c13dc..680e234 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -923,9 +923,16 @@ again:
path2->slots[level]--;
eb = path2->nodes[level];
- WARN_ON(btrfs_node_blockptr(eb, path2->slots[level]) !=
- cur->bytenr);
-
+ if (btrfs_node_blockptr(eb, path2->slots[level]) !=
+ cur->bytenr) {
+ btrfs_err(root->fs_info,
+ "couldn't find block (%llu) (level %d) in tree (%llu) with key (%llu %u %llu)",
+ cur->bytenr, level - 1, root->objectid,
+ node_key->objectid, node_key->type,
+ node_key->offset);
+ err = -ENOENT;
+ goto out;
+ }
lower = cur;
need_check = true;
for (; level < BTRFS_MAX_LEVEL; level++) {
@@ -2686,11 +2693,15 @@ static int do_relocation(struct btrfs_trans_handle *trans,
if (!upper->eb) {
ret = btrfs_search_slot(trans, root, key, path, 0, 1);
- if (ret < 0) {
- err = ret;
+ if (ret) {
+ if (ret < 0)
+ err = ret;
+ else
+ err = -ENOENT;
+
+ btrfs_release_path(path);
break;
}
- BUG_ON(ret > 0);
if (!upper->eb) {
upper->eb = path->nodes[upper->level];
--
2.5.5
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Btrfs: return gracefully from balance if fs tree is corrupted
2016-09-14 15:51 [PATCH] Btrfs: return gracefully from balance if fs tree is corrupted Liu Bo
@ 2016-09-14 17:04 ` Josef Bacik
0 siblings, 0 replies; 2+ messages in thread
From: Josef Bacik @ 2016-09-14 17:04 UTC (permalink / raw)
To: Liu Bo, linux-btrfs; +Cc: David Sterba
On 09/14/2016 11:51 AM, Liu Bo wrote:
> When relocating tree blocks, we firstly get block information from
> back references in the extent tree, we then search fs tree to try to
> find all parents of a block.
>
> However, if fs tree is corrupted, eg. if there're some missing
> items, we could come across these WARN_ONs and BUG_ONs.
>
> This makes us print some error messages and return gracefully
> from balance.
>
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> ---
> fs/btrfs/relocation.c | 23 +++++++++++++++++------
> 1 file changed, 17 insertions(+), 6 deletions(-)
>
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index c0c13dc..680e234 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -923,9 +923,16 @@ again:
> path2->slots[level]--;
>
> eb = path2->nodes[level];
> - WARN_ON(btrfs_node_blockptr(eb, path2->slots[level]) !=
> - cur->bytenr);
> -
> + if (btrfs_node_blockptr(eb, path2->slots[level]) !=
> + cur->bytenr) {
> + btrfs_err(root->fs_info,
> + "couldn't find block (%llu) (level %d) in tree (%llu) with key (%llu %u %llu)",
> + cur->bytenr, level - 1, root->objectid,
> + node_key->objectid, node_key->type,
> + node_key->offset);
> + err = -ENOENT;
> + goto out;
> + }
> lower = cur;
> need_check = true;
> for (; level < BTRFS_MAX_LEVEL; level++) {
> @@ -2686,11 +2693,15 @@ static int do_relocation(struct btrfs_trans_handle *trans,
>
> if (!upper->eb) {
> ret = btrfs_search_slot(trans, root, key, path, 0, 1);
> - if (ret < 0) {
> - err = ret;
> + if (ret) {
> + if (ret < 0)
> + err = ret;
> + else
> + err = -ENOENT;
> +
> + btrfs_release_path(path);
> break;
> }
> - BUG_ON(ret > 0);
>
> if (!upper->eb) {
> upper->eb = path->nodes[upper->level];
>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Thanks,
Josef
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-14 17:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-14 15:51 [PATCH] Btrfs: return gracefully from balance if fs tree is corrupted Liu Bo
2016-09-14 17:04 ` Josef Bacik
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.