diff options
author | Kent Overstreet <[email protected]> | 2022-07-16 23:21:15 -0400 |
---|---|---|
committer | Kent Overstreet <[email protected]> | 2023-10-22 17:09:35 -0400 |
commit | c7a09cb1b13995da938f4e1df52adeba44515d7d (patch) | |
tree | 925b629759aa24e3ecd042a269f6a8876b84e311 | |
parent | 35f1a5034d81416ca820032452bed583f78f1f5e (diff) |
bcachefs: When fsck finds redundant snapshot keys, trigger snapshots cleanup
Fsck now checks for keys in different snapshot IDs that are now
redundant due to other snapshots being deleted - it needs to for its own
algorithms to not get confused.
When it detects this it should re-run the post snapshot deletion cleanup
- this patch does that.
Signed-off-by: Kent Overstreet <[email protected]>
-rw-r--r-- | fs/bcachefs/errcode.h | 1 | ||||
-rw-r--r-- | fs/bcachefs/fsck.c | 13 |
2 files changed, 12 insertions, 2 deletions
diff --git a/fs/bcachefs/errcode.h b/fs/bcachefs/errcode.h index f7d12915c1cc..0581f3c7a0d8 100644 --- a/fs/bcachefs/errcode.h +++ b/fs/bcachefs/errcode.h @@ -7,6 +7,7 @@ enum { OPEN_BUCKETS_EMPTY = 2048, FREELIST_EMPTY, /* Allocator thread not keeping up */ INSUFFICIENT_DEVICES, + NEED_SNAPSHOT_CLEANUP, }; #endif /* _BCACHFES_ERRCODE_H */ diff --git a/fs/bcachefs/fsck.c b/fs/bcachefs/fsck.c index 43575d7e050e..b401c0913bdc 100644 --- a/fs/bcachefs/fsck.c +++ b/fs/bcachefs/fsck.c @@ -512,7 +512,7 @@ static int snapshots_seen_update(struct bch_fs *c, struct snapshots_seen *s, bch2_btree_ids[btree_id], pos.inode, pos.offset, i->id, n.id, n.equiv); - return -EINVAL; + return -NEED_SNAPSHOT_CLEANUP; } return 0; @@ -2388,7 +2388,9 @@ static int fix_reflink_p(struct bch_fs *c) */ int bch2_fsck_full(struct bch_fs *c) { - return bch2_fs_check_snapshots(c) ?: + int ret; +again: + ret = bch2_fs_check_snapshots(c) ?: bch2_fs_check_subvols(c) ?: bch2_delete_dead_snapshots(c) ?: check_inodes(c, true) ?: @@ -2399,6 +2401,13 @@ int bch2_fsck_full(struct bch_fs *c) check_directory_structure(c) ?: check_nlinks(c) ?: fix_reflink_p(c); + + if (ret == -NEED_SNAPSHOT_CLEANUP) { + set_bit(BCH_FS_HAVE_DELETED_SNAPSHOTS, &c->flags); + goto again; + } + + return ret; } int bch2_fsck_walk_inodes_only(struct bch_fs *c) |