Skip to content

Commit eef0dc0

Browse files
committed
Merge tag 'bcachefs-2025-04-24' of git://evilpiepirate.org/bcachefs
Pull bcachefs fixes from Kent Overstreet: - Case insensitive directories now work - Ciemap now correctly reports on unwritten pagecache data - bcachefs tools 1.25.1 was incorrectly picking unaligned bucket sizes; fix journal and write path bugs this uncovered And assorted smaller fixes... * tag 'bcachefs-2025-04-24' of git://evilpiepirate.org/bcachefs: (24 commits) bcachefs: Rework fiemap transaction restart handling bcachefs: add fiemap delalloc extent detection bcachefs: refactor fiemap processing into extent helper and struct bcachefs: track current fiemap offset in start variable bcachefs: drop duplicate fiemap sync flag bcachefs: Fix btree_iter_peek_prev() at end of inode bcachefs: Make btree_iter_peek_prev() assert more precise bcachefs: Unit test fixes bcachefs: Print mount opts earlier bcachefs: unlink: casefold d_invalidate bcachefs: Fix casefold lookups bcachefs: Casefold is now a regular opts.h option bcachefs: Implement fileattr_(get|set) bcachefs: Allocator now copes with unaligned buckets bcachefs: Start copygc, rebalance threads earlier bcachefs: Refactor bch2_run_recovery_passes() bcachefs: bch2_copygc_wakeup() bcachefs: Fix ref leak in write_super() bcachefs: Change __journal_entry_close() assert to ERO bcachefs: Ensure journal space is block size aligned ...
2 parents 02ddfb9 + d1b0f9a commit eef0dc0

32 files changed

+735
-585
lines changed

fs/bcachefs/alloc_foreground.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,8 @@ int bch2_alloc_sectors_start_trans(struct btree_trans *trans,
14251425
open_bucket_for_each(c, &wp->ptrs, ob, i)
14261426
wp->sectors_free = min(wp->sectors_free, ob->sectors_free);
14271427

1428+
wp->sectors_free = rounddown(wp->sectors_free, block_sectors(c));
1429+
14281430
BUG_ON(!wp->sectors_free || wp->sectors_free == UINT_MAX);
14291431

14301432
return 0;

fs/bcachefs/alloc_foreground.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ static inline void bch2_alloc_sectors_done_inlined(struct bch_fs *c, struct writ
110110
unsigned i;
111111

112112
open_bucket_for_each(c, &wp->ptrs, ob, i)
113-
ob_push(c, !ob->sectors_free ? &ptrs : &keep, ob);
113+
ob_push(c, ob->sectors_free < block_sectors(c)
114+
? &ptrs
115+
: &keep, ob);
114116
wp->ptrs = keep;
115117

116118
mutex_unlock(&wp->lock);

fs/bcachefs/bcachefs_format.h

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ static inline void bkey_init(struct bkey *k)
366366
#define __BKEY_PADDED(key, pad) \
367367
struct bkey_i key; __u64 key ## _pad[pad]
368368

369+
enum bch_bkey_type_flags {
370+
BKEY_TYPE_strict_btree_checks = BIT(0),
371+
};
372+
369373
/*
370374
* - DELETED keys are used internally to mark keys that should be ignored but
371375
* override keys in composition order. Their version number is ignored.
@@ -383,46 +387,46 @@ static inline void bkey_init(struct bkey *k)
383387
*
384388
* - WHITEOUT: for hash table btrees
385389
*/
386-
#define BCH_BKEY_TYPES() \
387-
x(deleted, 0) \
388-
x(whiteout, 1) \
389-
x(error, 2) \
390-
x(cookie, 3) \
391-
x(hash_whiteout, 4) \
392-
x(btree_ptr, 5) \
393-
x(extent, 6) \
394-
x(reservation, 7) \
395-
x(inode, 8) \
396-
x(inode_generation, 9) \
397-
x(dirent, 10) \
398-
x(xattr, 11) \
399-
x(alloc, 12) \
400-
x(quota, 13) \
401-
x(stripe, 14) \
402-
x(reflink_p, 15) \
403-
x(reflink_v, 16) \
404-
x(inline_data, 17) \
405-
x(btree_ptr_v2, 18) \
406-
x(indirect_inline_data, 19) \
407-
x(alloc_v2, 20) \
408-
x(subvolume, 21) \
409-
x(snapshot, 22) \
410-
x(inode_v2, 23) \
411-
x(alloc_v3, 24) \
412-
x(set, 25) \
413-
x(lru, 26) \
414-
x(alloc_v4, 27) \
415-
x(backpointer, 28) \
416-
x(inode_v3, 29) \
417-
x(bucket_gens, 30) \
418-
x(snapshot_tree, 31) \
419-
x(logged_op_truncate, 32) \
420-
x(logged_op_finsert, 33) \
421-
x(accounting, 34) \
422-
x(inode_alloc_cursor, 35)
390+
#define BCH_BKEY_TYPES() \
391+
x(deleted, 0, 0) \
392+
x(whiteout, 1, 0) \
393+
x(error, 2, 0) \
394+
x(cookie, 3, 0) \
395+
x(hash_whiteout, 4, BKEY_TYPE_strict_btree_checks) \
396+
x(btree_ptr, 5, BKEY_TYPE_strict_btree_checks) \
397+
x(extent, 6, BKEY_TYPE_strict_btree_checks) \
398+
x(reservation, 7, BKEY_TYPE_strict_btree_checks) \
399+
x(inode, 8, BKEY_TYPE_strict_btree_checks) \
400+
x(inode_generation, 9, BKEY_TYPE_strict_btree_checks) \
401+
x(dirent, 10, BKEY_TYPE_strict_btree_checks) \
402+
x(xattr, 11, BKEY_TYPE_strict_btree_checks) \
403+
x(alloc, 12, BKEY_TYPE_strict_btree_checks) \
404+
x(quota, 13, BKEY_TYPE_strict_btree_checks) \
405+
x(stripe, 14, BKEY_TYPE_strict_btree_checks) \
406+
x(reflink_p, 15, BKEY_TYPE_strict_btree_checks) \
407+
x(reflink_v, 16, BKEY_TYPE_strict_btree_checks) \
408+
x(inline_data, 17, BKEY_TYPE_strict_btree_checks) \
409+
x(btree_ptr_v2, 18, BKEY_TYPE_strict_btree_checks) \
410+
x(indirect_inline_data, 19, BKEY_TYPE_strict_btree_checks) \
411+
x(alloc_v2, 20, BKEY_TYPE_strict_btree_checks) \
412+
x(subvolume, 21, BKEY_TYPE_strict_btree_checks) \
413+
x(snapshot, 22, BKEY_TYPE_strict_btree_checks) \
414+
x(inode_v2, 23, BKEY_TYPE_strict_btree_checks) \
415+
x(alloc_v3, 24, BKEY_TYPE_strict_btree_checks) \
416+
x(set, 25, 0) \
417+
x(lru, 26, BKEY_TYPE_strict_btree_checks) \
418+
x(alloc_v4, 27, BKEY_TYPE_strict_btree_checks) \
419+
x(backpointer, 28, BKEY_TYPE_strict_btree_checks) \
420+
x(inode_v3, 29, BKEY_TYPE_strict_btree_checks) \
421+
x(bucket_gens, 30, BKEY_TYPE_strict_btree_checks) \
422+
x(snapshot_tree, 31, BKEY_TYPE_strict_btree_checks) \
423+
x(logged_op_truncate, 32, BKEY_TYPE_strict_btree_checks) \
424+
x(logged_op_finsert, 33, BKEY_TYPE_strict_btree_checks) \
425+
x(accounting, 34, BKEY_TYPE_strict_btree_checks) \
426+
x(inode_alloc_cursor, 35, BKEY_TYPE_strict_btree_checks)
423427

424428
enum bch_bkey_type {
425-
#define x(name, nr) KEY_TYPE_##name = nr,
429+
#define x(name, nr, ...) KEY_TYPE_##name = nr,
426430
BCH_BKEY_TYPES()
427431
#undef x
428432
KEY_TYPE_MAX,
@@ -863,6 +867,7 @@ LE64_BITMASK(BCH_SB_VERSION_INCOMPAT_ALLOWED,
863867
LE64_BITMASK(BCH_SB_SHARD_INUMS_NBITS, struct bch_sb, flags[6], 0, 4);
864868
LE64_BITMASK(BCH_SB_WRITE_ERROR_TIMEOUT,struct bch_sb, flags[6], 4, 14);
865869
LE64_BITMASK(BCH_SB_CSUM_ERR_RETRY_NR, struct bch_sb, flags[6], 14, 20);
870+
LE64_BITMASK(BCH_SB_CASEFOLD, struct bch_sb, flags[6], 22, 23);
866871

867872
static inline __u64 BCH_SB_COMPRESSION_TYPE(const struct bch_sb *sb)
868873
{

fs/bcachefs/bkey_methods.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "xattr.h"
2222

2323
const char * const bch2_bkey_types[] = {
24-
#define x(name, nr) #name,
24+
#define x(name, nr, ...) #name,
2525
BCH_BKEY_TYPES()
2626
#undef x
2727
NULL
@@ -115,7 +115,7 @@ static bool key_type_set_merge(struct bch_fs *c, struct bkey_s l, struct bkey_s_
115115
})
116116

117117
const struct bkey_ops bch2_bkey_ops[] = {
118-
#define x(name, nr) [KEY_TYPE_##name] = bch2_bkey_ops_##name,
118+
#define x(name, nr, ...) [KEY_TYPE_##name] = bch2_bkey_ops_##name,
119119
BCH_BKEY_TYPES()
120120
#undef x
121121
};
@@ -155,6 +155,12 @@ static u64 bch2_key_types_allowed[] = {
155155
#undef x
156156
};
157157

158+
static const enum bch_bkey_type_flags bch2_bkey_type_flags[] = {
159+
#define x(name, nr, flags) [KEY_TYPE_##name] = flags,
160+
BCH_BKEY_TYPES()
161+
#undef x
162+
};
163+
158164
const char *bch2_btree_node_type_str(enum btree_node_type type)
159165
{
160166
return type == BKEY_TYPE_btree ? "internal btree node" : bch2_btree_id_str(type - 1);
@@ -177,8 +183,18 @@ int __bch2_bkey_validate(struct bch_fs *c, struct bkey_s_c k,
177183
if (type >= BKEY_TYPE_NR)
178184
return 0;
179185

180-
bkey_fsck_err_on(k.k->type < KEY_TYPE_MAX &&
181-
(type == BKEY_TYPE_btree || (from.flags & BCH_VALIDATE_commit)) &&
186+
enum bch_bkey_type_flags bkey_flags = k.k->type < KEY_TYPE_MAX
187+
? bch2_bkey_type_flags[k.k->type]
188+
: 0;
189+
190+
bool strict_key_type_allowed =
191+
(from.flags & BCH_VALIDATE_commit) ||
192+
type == BKEY_TYPE_btree ||
193+
(from.btree < BTREE_ID_NR &&
194+
(bkey_flags & BKEY_TYPE_strict_btree_checks));
195+
196+
bkey_fsck_err_on(strict_key_type_allowed &&
197+
k.k->type < KEY_TYPE_MAX &&
182198
!(bch2_key_types_allowed[type] & BIT_ULL(k.k->type)),
183199
c, bkey_invalid_type_for_btree,
184200
"invalid key type for btree %s (%s)",

fs/bcachefs/btree_iter.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,7 +2577,10 @@ struct bkey_s_c bch2_btree_iter_peek_prev_min(struct btree_trans *trans, struct
25772577
struct bpos end)
25782578
{
25792579
if ((iter->flags & (BTREE_ITER_is_extents|BTREE_ITER_filter_snapshots)) &&
2580-
!bkey_eq(iter->pos, POS_MAX)) {
2580+
!bkey_eq(iter->pos, POS_MAX) &&
2581+
!((iter->flags & BTREE_ITER_is_extents) &&
2582+
iter->pos.offset == U64_MAX)) {
2583+
25812584
/*
25822585
* bkey_start_pos(), for extents, is not monotonically
25832586
* increasing until after filtering for snapshots:
@@ -2602,7 +2605,7 @@ struct bkey_s_c bch2_btree_iter_peek_prev_min(struct btree_trans *trans, struct
26022605

26032606
bch2_trans_verify_not_unlocked_or_in_restart(trans);
26042607
bch2_btree_iter_verify_entry_exit(iter);
2605-
EBUG_ON((iter->flags & BTREE_ITER_filter_snapshots) && bpos_eq(end, POS_MIN));
2608+
EBUG_ON((iter->flags & BTREE_ITER_filter_snapshots) && iter->pos.inode != end.inode);
26062609

26072610
int ret = trans_maybe_inject_restart(trans, _RET_IP_);
26082611
if (unlikely(ret)) {

fs/bcachefs/dirent.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
#include <linux/dcache.h>
1515

16-
static int bch2_casefold(struct btree_trans *trans, const struct bch_hash_info *info,
17-
const struct qstr *str, struct qstr *out_cf)
16+
int bch2_casefold(struct btree_trans *trans, const struct bch_hash_info *info,
17+
const struct qstr *str, struct qstr *out_cf)
1818
{
1919
*out_cf = (struct qstr) QSTR_INIT(NULL, 0);
2020

@@ -35,18 +35,6 @@ static int bch2_casefold(struct btree_trans *trans, const struct bch_hash_info *
3535
#endif
3636
}
3737

38-
static inline int bch2_maybe_casefold(struct btree_trans *trans,
39-
const struct bch_hash_info *info,
40-
const struct qstr *str, struct qstr *out_cf)
41-
{
42-
if (likely(!info->cf_encoding)) {
43-
*out_cf = *str;
44-
return 0;
45-
} else {
46-
return bch2_casefold(trans, info, str, out_cf);
47-
}
48-
}
49-
5038
static unsigned bch2_dirent_name_bytes(struct bkey_s_c_dirent d)
5139
{
5240
if (bkey_val_bytes(d.k) < offsetof(struct bch_dirent, d_name))

fs/bcachefs/dirent.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ struct bch_fs;
2323
struct bch_hash_info;
2424
struct bch_inode_info;
2525

26+
int bch2_casefold(struct btree_trans *, const struct bch_hash_info *,
27+
const struct qstr *, struct qstr *);
28+
29+
static inline int bch2_maybe_casefold(struct btree_trans *trans,
30+
const struct bch_hash_info *info,
31+
const struct qstr *str, struct qstr *out_cf)
32+
{
33+
if (likely(!info->cf_encoding)) {
34+
*out_cf = *str;
35+
return 0;
36+
} else {
37+
return bch2_casefold(trans, info, str, out_cf);
38+
}
39+
}
40+
2641
struct qstr bch2_dirent_get_name(struct bkey_s_c_dirent d);
2742

2843
static inline unsigned dirent_val_u64s(unsigned len, unsigned cf_len)

fs/bcachefs/error.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,6 @@ static struct fsck_err_state *fsck_err_get(struct bch_fs *c,
272272
{
273273
struct fsck_err_state *s;
274274

275-
if (!test_bit(BCH_FS_fsck_running, &c->flags))
276-
return NULL;
277-
278275
list_for_each_entry(s, &c->fsck_error_msgs, list)
279276
if (s->id == id) {
280277
/*
@@ -639,14 +636,14 @@ int __bch2_bkey_fsck_err(struct bch_fs *c,
639636
return ret;
640637
}
641638

642-
void bch2_flush_fsck_errs(struct bch_fs *c)
639+
static void __bch2_flush_fsck_errs(struct bch_fs *c, bool print)
643640
{
644641
struct fsck_err_state *s, *n;
645642

646643
mutex_lock(&c->fsck_error_msgs_lock);
647644

648645
list_for_each_entry_safe(s, n, &c->fsck_error_msgs, list) {
649-
if (s->ratelimited && s->last_msg)
646+
if (print && s->ratelimited && s->last_msg)
650647
bch_err(c, "Saw %llu errors like:\n %s", s->nr, s->last_msg);
651648

652649
list_del(&s->list);
@@ -657,6 +654,16 @@ void bch2_flush_fsck_errs(struct bch_fs *c)
657654
mutex_unlock(&c->fsck_error_msgs_lock);
658655
}
659656

657+
void bch2_flush_fsck_errs(struct bch_fs *c)
658+
{
659+
__bch2_flush_fsck_errs(c, true);
660+
}
661+
662+
void bch2_free_fsck_errs(struct bch_fs *c)
663+
{
664+
__bch2_flush_fsck_errs(c, false);
665+
}
666+
660667
int bch2_inum_offset_err_msg_trans(struct btree_trans *trans, struct printbuf *out,
661668
subvol_inum inum, u64 offset)
662669
{

fs/bcachefs/error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ int __bch2_fsck_err(struct bch_fs *, struct btree_trans *,
9393
_flags, BCH_FSCK_ERR_##_err_type, __VA_ARGS__)
9494

9595
void bch2_flush_fsck_errs(struct bch_fs *);
96+
void bch2_free_fsck_errs(struct bch_fs *);
9697

9798
#define fsck_err_wrap(_do) \
9899
({ \

0 commit comments

Comments
 (0)