linux-bcachefs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Overstreet <kent.overstreet@linux.dev>
To: linux-bcachefs@vger.kernel.org
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Subject: [PATCH 14/37] bcachefs: fsck: fix extent past end of inode repair
Date: Wed, 18 Jun 2025 17:54:05 -0400	[thread overview]
Message-ID: <20250618215431.738317-15-kent.overstreet@linux.dev> (raw)
In-Reply-To: <20250618215431.738317-1-kent.overstreet@linux.dev>

Fix the case where we're deleting in a different snapshot and need to
emit a whiteout - that requires a regular BTREE_ITER_filter_snapshots
iterator.

Also, only delete the part of the extent that extents past i_size.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 fs/bcachefs/fsck.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/fs/bcachefs/fsck.c b/fs/bcachefs/fsck.c
index 28ca07c0e029..48810a8e5d4b 100644
--- a/fs/bcachefs/fsck.c
+++ b/fs/bcachefs/fsck.c
@@ -1820,18 +1820,39 @@ static int check_extent(struct btree_trans *trans, struct btree_iter *iter,
 			    !key_visible_in_snapshot(c, s, i->inode.bi_snapshot, k.k->p.snapshot))
 				continue;
 
-			if (fsck_err_on(k.k->p.offset > round_up(i->inode.bi_size, block_bytes(c)) >> 9 &&
+			u64 last_block = round_up(i->inode.bi_size, block_bytes(c)) >> 9;
+
+			if (fsck_err_on(k.k->p.offset > last_block &&
 					!bkey_extent_is_reservation(k),
 					trans, extent_past_end_of_inode,
 					"extent type past end of inode %llu:%u, i_size %llu\n%s",
 					i->inode.bi_inum, i->inode.bi_snapshot, i->inode.bi_size,
 					(bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
-				struct btree_iter iter2;
+				struct bkey_i *whiteout = bch2_trans_kmalloc(trans, sizeof(*whiteout));
+				ret = PTR_ERR_OR_ZERO(whiteout);
+				if (ret)
+					goto err;
 
-				bch2_trans_copy_iter(trans, &iter2, iter);
-				bch2_btree_iter_set_snapshot(trans, &iter2, i->inode.bi_snapshot);
+				bkey_init(&whiteout->k);
+				whiteout->k.p = SPOS(k.k->p.inode,
+						     last_block,
+						     i->inode.bi_snapshot);
+				bch2_key_resize(&whiteout->k,
+						min(KEY_SIZE_MAX & (~0 << c->block_bits),
+						    U64_MAX - whiteout->k.p.offset));
+
+
+				/*
+				 * Need a normal (not BTREE_ITER_all_snapshots)
+				 * iterator, if we're deleting in a different
+				 * snapshot and need to emit a whiteout
+				 */
+				struct btree_iter iter2;
+				bch2_trans_iter_init(trans, &iter2, BTREE_ID_extents,
+						     bkey_start_pos(&whiteout->k),
+						     BTREE_ITER_intent);
 				ret =   bch2_btree_iter_traverse(trans, &iter2) ?:
-					bch2_btree_delete_at(trans, &iter2,
+					bch2_trans_update(trans, &iter2, whiteout,
 						BTREE_UPDATE_internal_snapshot_node);
 				bch2_trans_iter_exit(trans, &iter2);
 				if (ret)
-- 
2.50.0


  parent reply	other threads:[~2025-06-18 21:54 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18 21:53 [PATCH 00/37] 6.16-rc3 hotfixes series Kent Overstreet
2025-06-18 21:53 ` [PATCH 01/37] bcachefs: trace_extent_trim_atomic Kent Overstreet
2025-06-18 21:53 ` [PATCH 02/37] bcachefs: btree iter tracepoints Kent Overstreet
2025-06-18 21:53 ` [PATCH 03/37] bcachefs: Don't allocate new memory when mempool is exhausted Kent Overstreet
2025-06-18 21:53 ` [PATCH 04/37] bcachefs: Fix alloc_req use after free Kent Overstreet
2025-06-18 21:53 ` [PATCH 05/37] bcachefs: Add missing EBUG_ON Kent Overstreet
2025-06-18 21:53 ` [PATCH 06/37] bcachefs: Delay calculation of trans->journal_u64s Kent Overstreet
2025-06-18 21:53 ` [PATCH 07/37] bcachefs: Fix bch2_journal_keys_peek_prev_min() Kent Overstreet
2025-06-18 21:53 ` [PATCH 08/37] bcachefs: btree_iter: fix updates, journal overlay Kent Overstreet
2025-06-18 21:54 ` [PATCH 09/37] bcachefs: better __bch2_snapshot_is_ancestor() assert Kent Overstreet
2025-06-18 21:54 ` [PATCH 10/37] bcachefs: pass last_seq into fs_journal_start() Kent Overstreet
2025-06-18 21:54 ` [PATCH 11/37] bcachefs: Fix "now allowing incompatible features" message Kent Overstreet
2025-06-18 21:54 ` [PATCH 12/37] bcachefs: Fix snapshot_key_missing_inode_snapshot repair Kent Overstreet
2025-06-18 21:54 ` [PATCH 13/37] bcachefs: fsck: fix add_inode() Kent Overstreet
2025-06-18 21:54 ` Kent Overstreet [this message]
2025-06-18 21:54 ` [PATCH 15/37] bcachefs: opts.journal_rewind Kent Overstreet
2025-06-18 21:54 ` [PATCH 16/37] bcachefs: Kill unused tracepoints Kent Overstreet
2025-06-18 21:54 ` [PATCH 17/37] bcachefs: mark more errors autofix Kent Overstreet
2025-06-18 21:54 ` [PATCH 18/37] bcachefs: Move bset size check before csum check Kent Overstreet
2025-06-18 21:54 ` [PATCH 19/37] bcachefs: Fix pool->alloc NULL pointer dereference Kent Overstreet
2025-06-18 21:54 ` [PATCH 20/37] bcachefs: don't return fsck_fix for unfixable node errors in __btree_err Kent Overstreet
2025-06-18 21:54 ` [PATCH 21/37] bcachefs: fsck: Improve check_key_has_inode() Kent Overstreet
2025-06-18 21:54 ` [PATCH 22/37] bcachefs: Call bch2_fs_init_rw() early if we'll be going rw Kent Overstreet
2025-06-18 21:54 ` [PATCH 23/37] bcachefs: Fix __bch2_inum_to_path() when crossing subvol boundaries Kent Overstreet
2025-06-18 21:54 ` [PATCH 24/37] bcachefs: fsck: Print path when we find a subvol loop Kent Overstreet
2025-06-18 21:54 ` [PATCH 25/37] bcachefs: fsck: Fix remove_backpointer() for subvol roots Kent Overstreet
2025-06-18 21:54 ` [PATCH 26/37] bcachefs: fsck: Fix reattach_inode() " Kent Overstreet
2025-06-18 21:54 ` [PATCH 27/37] bcachefs: fsck: check_directory_structure runs in reverse order Kent Overstreet
2025-06-18 21:54 ` [PATCH 28/37] bcachefs: fsck: additional diagnostics for reattach_inode() Kent Overstreet
2025-06-18 21:54 ` [PATCH 29/37] bcachefs: fsck: check_subdir_count logs path Kent Overstreet
2025-06-18 21:54 ` [PATCH 30/37] bcachefs: fsck: Fix check_path_loop() + snapshots Kent Overstreet
2025-06-18 21:54 ` [PATCH 31/37] bcachefs: Fix bch2_read_bio_to_text() Kent Overstreet
2025-06-18 21:54 ` [PATCH 32/37] bcachefs: Fix restart handling in btree_node_scrub_work() Kent Overstreet
2025-06-18 21:54 ` [PATCH 33/37] bcachefs: fsck: Fix check_directory_structure when no check_dirents Kent Overstreet
2025-06-18 21:54 ` [PATCH 34/37] bcachefs: fsck: fix unhandled restart in topology repair Kent Overstreet
2025-06-18 21:54 ` [PATCH 35/37] bcachefs: fsck: Fix oops in key_visible_in_snapshot() Kent Overstreet
2025-06-18 21:54 ` [PATCH 36/37] bcachefs: fix spurious error in read_btree_roots() Kent Overstreet
2025-06-18 21:54 ` [PATCH 37/37] bcachefs: Fix missing newlines before ero Kent Overstreet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250618215431.738317-15-kent.overstreet@linux.dev \
    --to=kent.overstreet@linux.dev \
    --cc=linux-bcachefs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).