summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2025-06-26 19:55:40 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2025-06-30 17:52:46 -0400
commit747049b0437a6daf55dcf3ef4eb180c43ac070a2 (patch)
treebd1fc2e248b30d0912297fb78a995aeaa2f9684a
parenta217217d468239f0788c407885681c122671ff7f (diff)
bcachefs: Improve inode_create behaviour on old filesystemsfor-next
On filesystems that predate persistent cursors, inode_generation keys will be present (no longer needed because the cursor tracks the current generation). But the new inode allocation code skipped allocating slots with inode_generation keys, which led to a lot of unnecessary scanning, which this patch fixes. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/inode.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/fs/bcachefs/inode.c b/fs/bcachefs/inode.c
index 1c1b6e4533fc..307fb0c95656 100644
--- a/fs/bcachefs/inode.c
+++ b/fs/bcachefs/inode.c
@@ -1018,6 +1018,7 @@ int bch2_inode_create(struct btree_trans *trans,
u64 start = le64_to_cpu(cursor->v.idx);
u64 pos = start;
+ u64 gen = 0;
bch2_trans_iter_init(trans, iter, BTREE_ID_inodes, POS(0, pos),
BTREE_ITER_all_snapshots|
@@ -1030,6 +1031,12 @@ again:
if (pos < iter->pos.offset)
goto found_slot;
+ if (bch2_snapshot_is_ancestor(trans->c, snapshot, k.k->p.snapshot) &&
+ k.k->type == KEY_TYPE_inode_generation) {
+ gen = le32_to_cpu(bkey_s_c_to_inode_generation(k).v->bi_generation);
+ goto found_slot;
+ }
+
/*
* We don't need to iterate over keys in every snapshot once
* we've found just one:
@@ -1064,7 +1071,7 @@ found_slot:
}
inode_u->bi_inum = k.k->p.offset;
- inode_u->bi_generation = le64_to_cpu(cursor->v.gen);
+ inode_u->bi_generation = max(gen, le64_to_cpu(cursor->v.gen));
cursor->v.idx = cpu_to_le64(k.k->p.offset + 1);
return 0;
}