bcachefs: Kill ERO for i_blocks check in truncate
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 1 May 2025 04:01:29 +0000 (00:01 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 1 May 2025 10:19:58 +0000 (06:19 -0400)
Replace with logging the error in the superblock.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fs-io.c
fs/bcachefs/sb-errors_format.h

index 28619b6bd327038517318041a323e50f83eb1437..9657144666b8b278ed9598027851e3baa031b3bc 100644 (file)
@@ -517,11 +517,22 @@ int bchfs_truncate(struct mnt_idmap *idmap,
                goto err;
        }
 
-       bch2_fs_inconsistent_on(!inode->v.i_size && inode->v.i_blocks &&
-                               !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(!inode->v.i_size && inode->v.i_blocks &&
+                    !bch2_journal_error(&c->journal))) {
+               struct printbuf buf = PRINTBUF;
+               bch2_log_msg_start(c, &buf);
+               prt_printf(&buf,
+                          "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);
+
+               bool repeat = false, print = false, suppress = false;
+               bch2_count_fsck_err(c, vfs_inode_i_blocks_not_zero_at_truncate, buf.buf,
+                                   &repeat, &print, &suppress);
+               if (print)
+                       bch2_print_str(c, buf.buf);
+               printbuf_exit(&buf);
+       }
 
        ret = bch2_setattr_nonsize(idmap, inode, iattr);
 err:
index 822a0b42432d9018521d5aa932ce27d4d8110cf5..3b69a924086fd57398502ba1b76f72d14c39eaaf 100644 (file)
@@ -238,6 +238,7 @@ enum bch_fsck_flags {
        x(inode_journal_seq_in_future,                          299,    FSCK_AUTOFIX)   \
        x(inode_i_sectors_underflow,                            312,    FSCK_AUTOFIX)   \
        x(vfs_inode_i_blocks_underflow,                         311,    FSCK_AUTOFIX)   \
+       x(vfs_inode_i_blocks_not_zero_at_truncate,              313,    FSCK_AUTOFIX)   \
        x(deleted_inode_but_clean,                              211,    FSCK_AUTOFIX)   \
        x(deleted_inode_missing,                                212,    FSCK_AUTOFIX)   \
        x(deleted_inode_is_dir,                                 213,    FSCK_AUTOFIX)   \
@@ -321,7 +322,7 @@ enum bch_fsck_flags {
        x(dirent_stray_data_after_cf_name,                      305,    0)              \
        x(rebalance_work_incorrectly_set,                       309,    FSCK_AUTOFIX)   \
        x(rebalance_work_incorrectly_unset,                     310,    FSCK_AUTOFIX)   \
-       x(MAX,                                                  313,    0)
+       x(MAX,                                                  314,    0)
 
 enum bch_sb_error_id {
 #define x(t, n, ...) BCH_FSCK_ERR_##t = n,