Skip to content

Commit a2c63a3

Browse files
committed
Merge tag 'bcachefs-2024-04-22' of https://evilpiepirate.org/git/bcachefs
Pull bcachefs fixes from Kent Overstreet: "Nothing too crazy in this one, and it looks like (fingers crossed) the recovery and repair issues are settling down - although there's going to be a long tail there, as we've still yet to really ramp up on error injection or syzbot. - fix a few more deadlocks in recovery - fix u32/u64 issues in mi_btree_bitmap - btree key cache shrinker now actually frees, with more instrumentation coming so we can verify that it's working correctly more easily in the future" * tag 'bcachefs-2024-04-22' of https://evilpiepirate.org/git/bcachefs: bcachefs: If we run merges at a lower watermark, they must be nonblocking bcachefs: Fix inode early destruction path bcachefs: Fix deadlock in journal write path bcachefs: Tweak btree key cache shrinker so it actually frees bcachefs: bkey_cached.btree_trans_barrier_seq needs to be a ulong bcachefs: Fix missing call to bch2_fs_allocator_background_exit() bcachefs: Check for journal entries overruning end of sb clean section bcachefs: Fix bio alloc in check_extent_checksum() bcachefs: fix leak in bch2_gc_write_reflink_key bcachefs: KEY_TYPE_error is allowed for reflink bcachefs: Fix bch2_dev_btree_bitmap_marked_sectors() shift bcachefs: make sure to release last journal pin in replay bcachefs: node scan: ignore multiple nodes with same seq if interior bcachefs: Fix format specifier in validate_bset_keys() bcachefs: Fix null ptr deref in twf from BCH_IOCTL_FSCK_OFFLINE
2 parents 1c582ec + e858bee commit a2c63a3

19 files changed

+105
-52
lines changed

fs/bcachefs/backpointers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ static int check_extent_checksum(struct btree_trans *trans,
470470
goto err;
471471
}
472472

473-
bio = bio_alloc(ca->disk_sb.bdev, 1, REQ_OP_READ, GFP_KERNEL);
473+
bio = bio_alloc(ca->disk_sb.bdev, buf_pages(data_buf, bytes), REQ_OP_READ, GFP_KERNEL);
474474
bio->bi_iter.bi_sector = p.ptr.offset;
475475
bch2_bio_map(bio, data_buf, bytes);
476476
ret = submit_bio_wait(bio);

fs/bcachefs/bcachefs_format.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,8 @@ enum btree_id_flags {
15041504
BIT_ULL(KEY_TYPE_stripe)) \
15051505
x(reflink, 7, BTREE_ID_EXTENTS|BTREE_ID_DATA, \
15061506
BIT_ULL(KEY_TYPE_reflink_v)| \
1507-
BIT_ULL(KEY_TYPE_indirect_inline_data)) \
1507+
BIT_ULL(KEY_TYPE_indirect_inline_data)| \
1508+
BIT_ULL(KEY_TYPE_error)) \
15081509
x(subvolumes, 8, 0, \
15091510
BIT_ULL(KEY_TYPE_subvolume)) \
15101511
x(snapshots, 9, 0, \

fs/bcachefs/btree_gc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1587,14 +1587,15 @@ static int bch2_gc_write_reflink_key(struct btree_trans *trans,
15871587
struct bkey_i *new = bch2_bkey_make_mut_noupdate(trans, k);
15881588
ret = PTR_ERR_OR_ZERO(new);
15891589
if (ret)
1590-
return ret;
1590+
goto out;
15911591

15921592
if (!r->refcount)
15931593
new->k.type = KEY_TYPE_deleted;
15941594
else
15951595
*bkey_refcount(bkey_i_to_s(new)) = cpu_to_le64(r->refcount);
15961596
ret = bch2_trans_update(trans, iter, new, 0);
15971597
}
1598+
out:
15981599
fsck_err:
15991600
printbuf_exit(&buf);
16001601
return ret;

fs/bcachefs/btree_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ static int validate_bset_keys(struct bch_fs *c, struct btree *b,
888888
-BCH_ERR_btree_node_read_err_fixable,
889889
c, NULL, b, i,
890890
btree_node_bkey_bad_u64s,
891-
"bad k->u64s %u (min %u max %lu)", k->u64s,
891+
"bad k->u64s %u (min %u max %zu)", k->u64s,
892892
bkeyp_key_u64s(&b->format, k),
893893
U8_MAX - BKEY_U64s + bkeyp_key_u64s(&b->format, k)))
894894
goto drop_this_key;

fs/bcachefs/btree_key_cache.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,6 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
842842
* Newest freed entries are at the end of the list - once we hit one
843843
* that's too new to be freed, we can bail out:
844844
*/
845-
scanned += bc->nr_freed_nonpcpu;
846-
847845
list_for_each_entry_safe(ck, t, &bc->freed_nonpcpu, list) {
848846
if (!poll_state_synchronize_srcu(&c->btree_trans_barrier,
849847
ck->btree_trans_barrier_seq))
@@ -857,11 +855,6 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
857855
bc->nr_freed_nonpcpu--;
858856
}
859857

860-
if (scanned >= nr)
861-
goto out;
862-
863-
scanned += bc->nr_freed_pcpu;
864-
865858
list_for_each_entry_safe(ck, t, &bc->freed_pcpu, list) {
866859
if (!poll_state_synchronize_srcu(&c->btree_trans_barrier,
867860
ck->btree_trans_barrier_seq))
@@ -875,9 +868,6 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
875868
bc->nr_freed_pcpu--;
876869
}
877870

878-
if (scanned >= nr)
879-
goto out;
880-
881871
rcu_read_lock();
882872
tbl = rht_dereference_rcu(bc->table.tbl, &bc->table);
883873
if (bc->shrink_iter >= tbl->size)
@@ -893,12 +883,12 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
893883
next = rht_dereference_bucket_rcu(pos->next, tbl, bc->shrink_iter);
894884
ck = container_of(pos, struct bkey_cached, hash);
895885

896-
if (test_bit(BKEY_CACHED_DIRTY, &ck->flags))
886+
if (test_bit(BKEY_CACHED_DIRTY, &ck->flags)) {
897887
goto next;
898-
899-
if (test_bit(BKEY_CACHED_ACCESSED, &ck->flags))
888+
} else if (test_bit(BKEY_CACHED_ACCESSED, &ck->flags)) {
900889
clear_bit(BKEY_CACHED_ACCESSED, &ck->flags);
901-
else if (bkey_cached_lock_for_evict(ck)) {
890+
goto next;
891+
} else if (bkey_cached_lock_for_evict(ck)) {
902892
bkey_cached_evict(bc, ck);
903893
bkey_cached_free(bc, ck);
904894
}
@@ -916,7 +906,6 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
916906
} while (scanned < nr && bc->shrink_iter != start);
917907

918908
rcu_read_unlock();
919-
out:
920909
memalloc_nofs_restore(flags);
921910
srcu_read_unlock(&c->btree_trans_barrier, srcu_idx);
922911
mutex_unlock(&bc->lock);

fs/bcachefs/btree_node_scan.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ static int handle_overwrites(struct bch_fs *c,
302302

303303
start->max_key = bpos_predecessor(n->min_key);
304304
start->range_updated = true;
305+
} else if (n->level) {
306+
n->overwritten = true;
305307
} else {
306308
struct printbuf buf = PRINTBUF;
307309

fs/bcachefs/btree_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ struct bkey_cached {
321321
struct btree_bkey_cached_common c;
322322

323323
unsigned long flags;
324+
unsigned long btree_trans_barrier_seq;
324325
u16 u64s;
325326
bool valid;
326-
u32 btree_trans_barrier_seq;
327327
struct bkey_cached_key key;
328328

329329
struct rhash_head hash;

fs/bcachefs/btree_update_interior.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,11 @@ int __bch2_foreground_maybe_merge(struct btree_trans *trans,
19601960
if ((flags & BCH_WATERMARK_MASK) == BCH_WATERMARK_interior_updates)
19611961
return 0;
19621962

1963-
flags &= ~BCH_WATERMARK_MASK;
1963+
if ((flags & BCH_WATERMARK_MASK) <= BCH_WATERMARK_reclaim) {
1964+
flags &= ~BCH_WATERMARK_MASK;
1965+
flags |= BCH_WATERMARK_btree;
1966+
flags |= BCH_TRANS_COMMIT_journal_reclaim;
1967+
}
19641968

19651969
b = trans->paths[path].l[level].b;
19661970

fs/bcachefs/chardev.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,15 @@ static long bch2_ioctl_fsck_offline(struct bch_ioctl_fsck_offline __user *user_a
232232
/* We need request_key() to be called before we punt to kthread: */
233233
opt_set(thr->opts, nostart, true);
234234

235+
bch2_thread_with_stdio_init(&thr->thr, &bch2_offline_fsck_ops);
236+
235237
thr->c = bch2_fs_open(devs.data, arg.nr_devs, thr->opts);
236238

237239
if (!IS_ERR(thr->c) &&
238240
thr->c->opts.errors == BCH_ON_ERROR_panic)
239241
thr->c->opts.errors = BCH_ON_ERROR_ro;
240242

241-
ret = bch2_run_thread_with_stdio(&thr->thr, &bch2_offline_fsck_ops);
243+
ret = __bch2_run_thread_with_stdio(&thr->thr);
242244
out:
243245
darray_for_each(devs, i)
244246
kfree(*i);

fs/bcachefs/fs.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ static struct bch_inode_info *bch2_inode_insert(struct bch_fs *c, struct bch_ino
188188
BUG_ON(!old);
189189

190190
if (unlikely(old != inode)) {
191-
discard_new_inode(&inode->v);
191+
__destroy_inode(&inode->v);
192+
kmem_cache_free(bch2_inode_cache, inode);
192193
inode = old;
193194
} else {
194195
mutex_lock(&c->vfs_inodes_lock);
@@ -225,8 +226,10 @@ static struct bch_inode_info *bch2_new_inode(struct btree_trans *trans)
225226

226227
if (unlikely(!inode)) {
227228
int ret = drop_locks_do(trans, (inode = to_bch_ei(new_inode(c->vfs_sb))) ? 0 : -ENOMEM);
228-
if (ret && inode)
229-
discard_new_inode(&inode->v);
229+
if (ret && inode) {
230+
__destroy_inode(&inode->v);
231+
kmem_cache_free(bch2_inode_cache, inode);
232+
}
230233
if (ret)
231234
return ERR_PTR(ret);
232235
}

0 commit comments

Comments
 (0)