summaryrefslogtreecommitdiff
path: root/fs/bcachefs/fsck.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2025-02-25 20:42:40 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2025-02-25 20:56:41 -0500
commit559ae9ec988de991142b6a067c313aeb530c2b11 (patch)
tree20b43ec46f0b3350ea0a15391150e8f6ede58ffb /fs/bcachefs/fsck.c
parent82af8187566114f55114f1b878562de031e0b9b4 (diff)
bcachefs: bcachefs_metadata_version_directory_size_v2bcachefs-dir-i-size
Co-developed-by: Hongbo Li <lihongbo22@huawei.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/fsck.c')
-rw-r--r--fs/bcachefs/fsck.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/fs/bcachefs/fsck.c b/fs/bcachefs/fsck.c
index 0e85131d0af8..a9480bb308b2 100644
--- a/fs/bcachefs/fsck.c
+++ b/fs/bcachefs/fsck.c
@@ -1978,10 +1978,31 @@ fsck_err:
return ret;
}
+static int check_dir_i_size_notnested(struct btree_trans *trans, struct inode_walker *w)
+{
+ struct bch_fs *c = trans->c;
+ int ret = 0;
+
+ darray_for_each(w->inodes, i)
+ if (fsck_err_on(i->inode.bi_size != i->i_size,
+ trans, inode_dir_wrong_nlink,
+ "directory %llu:%u with wrong i_size: got %llu, should be %llu",
+ w->last_pos.inode, i->snapshot, i->inode.bi_size, i->i_size)) {
+ i->inode.bi_size = i->i_size;
+ ret = bch2_fsck_write_inode(trans, &i->inode);
+ if (ret)
+ break;
+ }
+fsck_err:
+ bch_err_fn(c, ret);
+ return ret;
+}
+
static int check_subdir_dirents_count(struct btree_trans *trans, struct inode_walker *w)
{
u32 restart_count = trans->restart_count;
return check_subdir_count_notnested(trans, w) ?:
+ check_dir_i_size_notnested(trans, w) ?:
trans_was_restarted(trans, restart_count);
}
@@ -2449,7 +2470,8 @@ int bch2_check_dirents(struct bch_fs *c)
POS(BCACHEFS_ROOT_INO, 0),
BTREE_ITER_prefetch|BTREE_ITER_all_snapshots, k,
check_dirent(trans, &iter, k, &hash_info, &dir, &target, &s)) ?:
- check_subdir_count_notnested(trans, &dir));
+ check_subdir_count_notnested(trans, &dir) ?:
+ check_dir_i_size_notnested(trans, &dir));
snapshots_seen_exit(&s);
inode_walker_exit(&dir);