Commit f7005e01 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Improve error message in fsck

Seeing the extents that were overlapping is highly useful for figuring
out what went wrong.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent f1d786a0
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h" #include "bcachefs.h"
#include "bkey_on_stack.h"
#include "btree_update.h" #include "btree_update.h"
#include "dirent.h" #include "dirent.h"
#include "error.h" #include "error.h"
...@@ -469,10 +470,12 @@ static int check_extents(struct bch_fs *c) ...@@ -469,10 +470,12 @@ static int check_extents(struct bch_fs *c)
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bkey prev = KEY(0, 0, 0); struct bkey_on_stack prev;
u64 i_sectors; u64 i_sectors;
int ret = 0; int ret = 0;
bkey_on_stack_init(&prev);
prev.k->k = KEY(0, 0, 0);
bch2_trans_init(&trans, c, BTREE_ITER_MAX, 0); bch2_trans_init(&trans, c, BTREE_ITER_MAX, 0);
bch_verbose(c, "checking extents"); bch_verbose(c, "checking extents");
...@@ -482,24 +485,24 @@ static int check_extents(struct bch_fs *c) ...@@ -482,24 +485,24 @@ static int check_extents(struct bch_fs *c)
BTREE_ITER_INTENT); BTREE_ITER_INTENT);
retry: retry:
for_each_btree_key_continue(iter, 0, k, ret) { for_each_btree_key_continue(iter, 0, k, ret) {
if (bkey_cmp(prev.p, bkey_start_pos(k.k)) > 0) { if (bkey_cmp(prev.k->k.p, bkey_start_pos(k.k)) > 0) {
char buf1[100]; char buf1[200];
char buf2[100]; char buf2[200];
bch2_bkey_to_text(&PBUF(buf1), &prev); bch2_bkey_val_to_text(&PBUF(buf1), c, bkey_i_to_s_c(prev.k));
bch2_bkey_to_text(&PBUF(buf2), k.k); bch2_bkey_val_to_text(&PBUF(buf2), c, k);
if (fsck_err(c, "overlapping extents: %s, %s", buf1, buf2)) { if (fsck_err(c, "overlapping extents:\n%s\n%s", buf1, buf2)) {
ret = __bch2_trans_do(&trans, NULL, NULL, ret = __bch2_trans_do(&trans, NULL, NULL,
BTREE_INSERT_NOFAIL| BTREE_INSERT_NOFAIL|
BTREE_INSERT_LAZY_RW, BTREE_INSERT_LAZY_RW,
bch2_fix_overlapping_extent(&trans, bch2_fix_overlapping_extent(&trans,
iter, k, prev.p)); iter, k, prev.k->k.p));
if (ret) if (ret)
goto err; goto err;
} }
} }
prev = *k.k; bkey_on_stack_reassemble(&prev, c, k);
ret = walk_inode(&trans, &w, k.k->p.inode); ret = walk_inode(&trans, &w, k.k->p.inode);
if (ret) if (ret)
...@@ -525,7 +528,8 @@ static int check_extents(struct bch_fs *c) ...@@ -525,7 +528,8 @@ static int check_extents(struct bch_fs *c)
!(w.inode.bi_flags & BCH_INODE_I_SECTORS_DIRTY) && !(w.inode.bi_flags & BCH_INODE_I_SECTORS_DIRTY) &&
w.inode.bi_sectors != w.inode.bi_sectors !=
(i_sectors = bch2_count_inode_sectors(&trans, w.cur_inum)), (i_sectors = bch2_count_inode_sectors(&trans, w.cur_inum)),
c, "i_sectors wrong: got %llu, should be %llu", c, "inode %llu has incorrect i_sectors: got %llu, should be %llu",
w.inode.bi_inum,
w.inode.bi_sectors, i_sectors)) { w.inode.bi_sectors, i_sectors)) {
struct bkey_inode_buf p; struct bkey_inode_buf p;
...@@ -567,6 +571,7 @@ static int check_extents(struct bch_fs *c) ...@@ -567,6 +571,7 @@ static int check_extents(struct bch_fs *c)
fsck_err: fsck_err:
if (ret == -EINTR) if (ret == -EINTR)
goto retry; goto retry;
bkey_on_stack_exit(&prev, c);
return bch2_trans_exit(&trans) ?: ret; return bch2_trans_exit(&trans) ?: ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment