Skip to content

Commit 3a72e36

Browse files
author
Kent Overstreet
committed
bcachefs: check for inode.bi_sectors underflow
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 05450c4 commit 3a72e36

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

fs/bcachefs/io_write.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,27 @@ static inline int bch2_extent_update_i_size_sectors(struct btree_trans *trans,
255255
}
256256

257257
if (i_sectors_delta) {
258+
s64 bi_sectors = le64_to_cpu(inode->v.bi_sectors);
259+
if (unlikely(bi_sectors + i_sectors_delta < 0)) {
260+
struct bch_fs *c = trans->c;
261+
struct printbuf buf = PRINTBUF;
262+
bch2_log_msg_start(c, &buf);
263+
prt_printf(&buf, "inode %llu i_sectors underflow: %lli + %lli < 0",
264+
extent_iter->pos.inode, bi_sectors, i_sectors_delta);
265+
266+
bool repeat = false, print = false, suppress = false;
267+
bch2_count_fsck_err(c, inode_i_sectors_underflow, buf.buf,
268+
&repeat, &print, &suppress);
269+
if (print)
270+
bch2_print_str(c, buf.buf);
271+
printbuf_exit(&buf);
272+
273+
if (i_sectors_delta < 0)
274+
i_sectors_delta = -bi_sectors;
275+
else
276+
i_sectors_delta = 0;
277+
}
278+
258279
le64_add_cpu(&inode->v.bi_sectors, i_sectors_delta);
259280
inode_update_flags = 0;
260281
}

fs/bcachefs/sb-errors_format.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ enum bch_fsck_flags {
236236
x(inode_has_child_snapshots_wrong, 287, 0) \
237237
x(inode_unreachable, 210, FSCK_AUTOFIX) \
238238
x(inode_journal_seq_in_future, 299, FSCK_AUTOFIX) \
239+
x(inode_i_sectors_underflow, 312, FSCK_AUTOFIX) \
239240
x(vfs_inode_i_blocks_underflow, 311, FSCK_AUTOFIX) \
240241
x(deleted_inode_but_clean, 211, FSCK_AUTOFIX) \
241242
x(deleted_inode_missing, 212, FSCK_AUTOFIX) \
@@ -320,7 +321,7 @@ enum bch_fsck_flags {
320321
x(dirent_stray_data_after_cf_name, 305, 0) \
321322
x(rebalance_work_incorrectly_set, 309, FSCK_AUTOFIX) \
322323
x(rebalance_work_incorrectly_unset, 310, FSCK_AUTOFIX) \
323-
x(MAX, 312, 0)
324+
x(MAX, 313, 0)
324325

325326
enum bch_sb_error_id {
326327
#define x(t, n, ...) BCH_FSCK_ERR_##t = n,

0 commit comments

Comments
 (0)