Skip to content

Commit 67199a4

Browse files
committed
Merge tag 'bcachefs-2024-04-01' of https://evilpiepirate.org/git/bcachefs
Pull bcachefs fixes from Kent Overstreet: "Lots of fixes for situations with extreme filesystem damage. One fix ("Fix journal pins in btree write buffer") applicable to normal usage; also a dio performance fix. New repair/construction code is in the final stages, should be ready in about a week. Anyone that lost btree interior nodes (or a variety of other damage) as a result of the splitbrain bug will be able to repair then" * tag 'bcachefs-2024-04-01' of https://evilpiepirate.org/git/bcachefs: (32 commits) bcachefs: On emergency shutdown, print out current journal sequence number bcachefs: Fix overlapping extent repair bcachefs: Fix remove_dirent() bcachefs: Logged op errors should be ignored bcachefs: Improve -o norecovery; opts.recovery_pass_limit bcachefs: bch2_run_explicit_recovery_pass_persistent() bcachefs: Ensure bch_sb_field_ext always exists bcachefs: Flush journal immediately after replay if we did early repair bcachefs: Resume logged ops after fsck bcachefs: Add error messages to logged ops fns bcachefs: Split out recovery_passes.c bcachefs: fix backpointer for missing alloc key msg bcachefs: Fix bch2_btree_increase_depth() bcachefs: Kill bch2_bkey_ptr_data_type() bcachefs: Fix use after free in check_root_trans() bcachefs: Fix repair path for missing indirect extents bcachefs: Fix use after free in bch2_check_fix_ptrs() bcachefs: Fix btree node keys accounting in topology repair path bcachefs: Check btree ptr min_key in .invalid bcachefs: add REQ_SYNC and REQ_IDLE in write dio ...
2 parents 026e680 + b3c7fd3 commit 67199a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+814
-646
lines changed

fs/bcachefs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ bcachefs-y := \
6767
quota.o \
6868
rebalance.o \
6969
recovery.o \
70+
recovery_passes.o \
7071
reflink.o \
7172
replicas.o \
7273
sb-clean.o \

fs/bcachefs/backpointers.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ static bool extent_matches_bp(struct bch_fs *c,
2929
if (p.ptr.cached)
3030
continue;
3131

32-
bch2_extent_ptr_to_bp(c, btree_id, level, k, p,
33-
&bucket2, &bp2);
32+
bch2_extent_ptr_to_bp(c, btree_id, level, k, p, entry, &bucket2, &bp2);
3433
if (bpos_eq(bucket, bucket2) &&
3534
!memcmp(&bp, &bp2, sizeof(bp)))
3635
return true;
@@ -44,6 +43,11 @@ int bch2_backpointer_invalid(struct bch_fs *c, struct bkey_s_c k,
4443
struct printbuf *err)
4544
{
4645
struct bkey_s_c_backpointer bp = bkey_s_c_to_backpointer(k);
46+
47+
/* these will be caught by fsck */
48+
if (!bch2_dev_exists2(c, bp.k->p.inode))
49+
return 0;
50+
4751
struct bpos bucket = bp_pos_to_bucket(c, bp.k->p);
4852
int ret = 0;
4953

@@ -378,7 +382,7 @@ static int bch2_check_btree_backpointer(struct btree_trans *trans, struct btree_
378382
backpointer_to_missing_alloc,
379383
"backpointer for nonexistent alloc key: %llu:%llu:0\n%s",
380384
alloc_iter.pos.inode, alloc_iter.pos.offset,
381-
(bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf))) {
385+
(bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
382386
ret = bch2_btree_delete_at(trans, bp_iter, 0);
383387
goto out;
384388
}
@@ -502,8 +506,7 @@ static int check_extent_to_backpointers(struct btree_trans *trans,
502506
if (p.ptr.cached)
503507
continue;
504508

505-
bch2_extent_ptr_to_bp(c, btree, level,
506-
k, p, &bucket_pos, &bp);
509+
bch2_extent_ptr_to_bp(c, btree, level, k, p, entry, &bucket_pos, &bp);
507510

508511
ret = check_bp_exists(trans, s, bucket_pos, bp, k);
509512
if (ret)

fs/bcachefs/backpointers.h

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,40 @@ static inline int bch2_bucket_backpointer_mod(struct btree_trans *trans,
9090
return bch2_trans_update_buffered(trans, BTREE_ID_backpointers, &bp_k.k_i);
9191
}
9292

93-
static inline enum bch_data_type bkey_ptr_data_type(enum btree_id btree_id, unsigned level,
94-
struct bkey_s_c k, struct extent_ptr_decoded p)
93+
static inline enum bch_data_type bch2_bkey_ptr_data_type(struct bkey_s_c k,
94+
struct extent_ptr_decoded p,
95+
const union bch_extent_entry *entry)
9596
{
96-
return level ? BCH_DATA_btree :
97-
p.has_ec ? BCH_DATA_stripe :
98-
BCH_DATA_user;
97+
switch (k.k->type) {
98+
case KEY_TYPE_btree_ptr:
99+
case KEY_TYPE_btree_ptr_v2:
100+
return BCH_DATA_btree;
101+
case KEY_TYPE_extent:
102+
case KEY_TYPE_reflink_v:
103+
return p.has_ec ? BCH_DATA_stripe : BCH_DATA_user;
104+
case KEY_TYPE_stripe: {
105+
const struct bch_extent_ptr *ptr = &entry->ptr;
106+
struct bkey_s_c_stripe s = bkey_s_c_to_stripe(k);
107+
108+
BUG_ON(ptr < s.v->ptrs ||
109+
ptr >= s.v->ptrs + s.v->nr_blocks);
110+
111+
return ptr >= s.v->ptrs + s.v->nr_blocks - s.v->nr_redundant
112+
? BCH_DATA_parity
113+
: BCH_DATA_user;
114+
}
115+
default:
116+
BUG();
117+
}
99118
}
100119

101120
static inline void bch2_extent_ptr_to_bp(struct bch_fs *c,
102121
enum btree_id btree_id, unsigned level,
103122
struct bkey_s_c k, struct extent_ptr_decoded p,
123+
const union bch_extent_entry *entry,
104124
struct bpos *bucket_pos, struct bch_backpointer *bp)
105125
{
106-
enum bch_data_type data_type = bkey_ptr_data_type(btree_id, level, k, p);
126+
enum bch_data_type data_type = bch2_bkey_ptr_data_type(k, p, entry);
107127
s64 sectors = level ? btree_sectors(c) : k.k->size;
108128
u32 bucket_offset;
109129

fs/bcachefs/bcachefs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
#include "fifo.h"
210210
#include "nocow_locking_types.h"
211211
#include "opts.h"
212-
#include "recovery_types.h"
212+
#include "recovery_passes_types.h"
213213
#include "sb-errors_types.h"
214214
#include "seqmutex.h"
215215
#include "time_stats.h"
@@ -810,7 +810,6 @@ struct bch_fs {
810810

811811
/* snapshot.c: */
812812
struct snapshot_table __rcu *snapshots;
813-
size_t snapshot_table_size;
814813
struct mutex snapshot_table_lock;
815814
struct rw_semaphore snapshot_create_lock;
816815

fs/bcachefs/bset.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,24 @@ void bch2_dump_btree_node_iter(struct btree *b,
134134
printbuf_exit(&buf);
135135
}
136136

137-
#ifdef CONFIG_BCACHEFS_DEBUG
138-
139-
void __bch2_verify_btree_nr_keys(struct btree *b)
137+
struct btree_nr_keys bch2_btree_node_count_keys(struct btree *b)
140138
{
141139
struct bset_tree *t;
142140
struct bkey_packed *k;
143-
struct btree_nr_keys nr = { 0 };
141+
struct btree_nr_keys nr = {};
144142

145143
for_each_bset(b, t)
146144
bset_tree_for_each_key(b, t, k)
147145
if (!bkey_deleted(k))
148146
btree_keys_account_key_add(&nr, t - b->set, k);
147+
return nr;
148+
}
149+
150+
#ifdef CONFIG_BCACHEFS_DEBUG
151+
152+
void __bch2_verify_btree_nr_keys(struct btree *b)
153+
{
154+
struct btree_nr_keys nr = bch2_btree_node_count_keys(b);
149155

150156
BUG_ON(memcmp(&nr, &b->nr, sizeof(nr)));
151157
}

fs/bcachefs/bset.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ struct bkey_s_c bch2_btree_node_iter_peek_unpack(struct btree_node_iter *,
458458

459459
/* Accounting: */
460460

461+
struct btree_nr_keys bch2_btree_node_count_keys(struct btree *);
462+
461463
static inline void btree_keys_account_key(struct btree_nr_keys *n,
462464
unsigned bset,
463465
struct bkey_packed *k,

fs/bcachefs/btree_cache.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,8 @@ static noinline void btree_bad_header(struct bch_fs *c, struct btree *b)
808808
prt_printf(&buf, "\nmax ");
809809
bch2_bpos_to_text(&buf, b->data->max_key);
810810

811-
bch2_fs_inconsistent(c, "%s", buf.buf);
811+
bch2_fs_topology_error(c, "%s", buf.buf);
812+
812813
printbuf_exit(&buf);
813814
}
814815

@@ -1134,6 +1135,8 @@ void bch2_btree_node_evict(struct btree_trans *trans, const struct bkey_i *k)
11341135
b = btree_cache_find(bc, k);
11351136
if (!b)
11361137
return;
1138+
1139+
BUG_ON(b == btree_node_root(trans->c, b));
11371140
wait_on_io:
11381141
/* not allowed to wait on io with btree locks held: */
11391142

0 commit comments

Comments
 (0)