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

bcachefs: Go emergency RO when i_blocks underflows

This improves some of our warnings and assertions - they imply possible
filesystem inconsistencies, so they should be calling
bch2_fs_inconsistent().
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 42796f74
...@@ -231,7 +231,10 @@ static void i_sectors_acct(struct bch_fs *c, struct bch_inode_info *inode, ...@@ -231,7 +231,10 @@ static void i_sectors_acct(struct bch_fs *c, struct bch_inode_info *inode,
return; return;
mutex_lock(&inode->ei_quota_lock); mutex_lock(&inode->ei_quota_lock);
BUG_ON((s64) inode->v.i_blocks + sectors < 0); bch2_fs_inconsistent_on((s64) inode->v.i_blocks + sectors < 0, c,
"inode %lu i_blocks underflow: %llu + %lli < 0 (ondisk %lli)",
inode->v.i_ino, (u64) inode->v.i_blocks, sectors,
inode->ei_inode.bi_sectors);
inode->v.i_blocks += sectors; inode->v.i_blocks += sectors;
#ifdef CONFIG_BCACHEFS_QUOTA #ifdef CONFIG_BCACHEFS_QUOTA
...@@ -2695,9 +2698,11 @@ int bch2_truncate(struct mnt_idmap *idmap, ...@@ -2695,9 +2698,11 @@ int bch2_truncate(struct mnt_idmap *idmap,
U64_MAX, &i_sectors_delta); U64_MAX, &i_sectors_delta);
i_sectors_acct(c, inode, NULL, i_sectors_delta); i_sectors_acct(c, inode, NULL, i_sectors_delta);
WARN_ON(!inode->v.i_size && inode->v.i_blocks && bch2_fs_inconsistent_on(!inode->v.i_size && inode->v.i_blocks &&
!bch2_journal_error(&c->journal)); !bch2_journal_error(&c->journal), c,
"inode %lu truncated to 0 but i_blocks %llu (ondisk %lli)",
inode->v.i_ino, (u64) inode->v.i_blocks,
inode->ei_inode.bi_sectors);
if (unlikely(ret)) if (unlikely(ret))
goto err; goto err;
......
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