Skip to content

Commit

Permalink
Update bcachefs sources to 035773e55b52 bcachefs: fix integer convers…
Browse files Browse the repository at this point in the history
…ion bug
  • Loading branch information
Kent Overstreet committed Apr 25, 2024
1 parent ec2d118 commit b9e48ed
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .bcachefs_revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0389c09b2fb702ca7924ddf550ce0c8af708b8be
035773e55b52cd87410b2cc319feb1981c74dab0
19 changes: 4 additions & 15 deletions libbcachefs/btree_key_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,6 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
* Newest freed entries are at the end of the list - once we hit one
* that's too new to be freed, we can bail out:
*/
scanned += bc->nr_freed_nonpcpu;

list_for_each_entry_safe(ck, t, &bc->freed_nonpcpu, list) {
if (!poll_state_synchronize_srcu(&c->btree_trans_barrier,
ck->btree_trans_barrier_seq))
Expand All @@ -857,11 +855,6 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
bc->nr_freed_nonpcpu--;
}

if (scanned >= nr)
goto out;

scanned += bc->nr_freed_pcpu;

list_for_each_entry_safe(ck, t, &bc->freed_pcpu, list) {
if (!poll_state_synchronize_srcu(&c->btree_trans_barrier,
ck->btree_trans_barrier_seq))
Expand All @@ -875,9 +868,6 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
bc->nr_freed_pcpu--;
}

if (scanned >= nr)
goto out;

rcu_read_lock();
tbl = rht_dereference_rcu(bc->table.tbl, &bc->table);
if (bc->shrink_iter >= tbl->size)
Expand All @@ -893,12 +883,12 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
next = rht_dereference_bucket_rcu(pos->next, tbl, bc->shrink_iter);
ck = container_of(pos, struct bkey_cached, hash);

if (test_bit(BKEY_CACHED_DIRTY, &ck->flags))
if (test_bit(BKEY_CACHED_DIRTY, &ck->flags)) {
goto next;

if (test_bit(BKEY_CACHED_ACCESSED, &ck->flags))
} else if (test_bit(BKEY_CACHED_ACCESSED, &ck->flags)) {
clear_bit(BKEY_CACHED_ACCESSED, &ck->flags);
else if (bkey_cached_lock_for_evict(ck)) {
goto next;
} else if (bkey_cached_lock_for_evict(ck)) {
bkey_cached_evict(bc, ck);
bkey_cached_free(bc, ck);
}
Expand All @@ -916,7 +906,6 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
} while (scanned < nr && bc->shrink_iter != start);

rcu_read_unlock();
out:
memalloc_nofs_restore(flags);
srcu_read_unlock(&c->btree_trans_barrier, srcu_idx);
mutex_unlock(&bc->lock);
Expand Down
7 changes: 5 additions & 2 deletions libbcachefs/btree_node_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,25 @@ static void found_btree_node_to_key(struct bkey_i *k, const struct found_btree_n
bp->v.seq = cpu_to_le64(f->cookie);
bp->v.sectors_written = 0;
bp->v.flags = 0;
bp->v.sectors_written = cpu_to_le16(f->sectors_written);
bp->v.min_key = f->min_key;
SET_BTREE_PTR_RANGE_UPDATED(&bp->v, f->range_updated);
memcpy(bp->v.start, f->ptrs, sizeof(struct bch_extent_ptr) * f->nr_ptrs);
}

static bool found_btree_node_is_readable(struct btree_trans *trans,
const struct found_btree_node *f)
struct found_btree_node *f)
{
struct { __BKEY_PADDED(k, BKEY_BTREE_PTR_VAL_U64s_MAX); } k;

found_btree_node_to_key(&k.k, f);

struct btree *b = bch2_btree_node_get_noiter(trans, &k.k, f->btree_id, f->level, false);
bool ret = !IS_ERR_OR_NULL(b);
if (ret)
if (ret) {
f->sectors_written = b->written;
six_unlock_read(&b->c.lock);
}

/*
* We might update this node's range; if that happens, we need the node
Expand Down
1 change: 1 addition & 0 deletions libbcachefs/btree_node_scan_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct found_btree_node {
bool overwritten:1;
u8 btree_id;
u8 level;
unsigned sectors_written;
u32 seq;
u64 cookie;

Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/btree_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ struct bkey_cached {
struct btree_bkey_cached_common c;

unsigned long flags;
unsigned long btree_trans_barrier_seq;
u16 u64s;
bool valid;
u32 btree_trans_barrier_seq;
struct bkey_cached_key key;

struct rhash_head hash;
Expand Down
6 changes: 5 additions & 1 deletion libbcachefs/btree_update_interior.c
Original file line number Diff line number Diff line change
Expand Up @@ -1960,7 +1960,11 @@ int __bch2_foreground_maybe_merge(struct btree_trans *trans,
if ((flags & BCH_WATERMARK_MASK) == BCH_WATERMARK_interior_updates)
return 0;

flags &= ~BCH_WATERMARK_MASK;
if ((flags & BCH_WATERMARK_MASK) <= BCH_WATERMARK_reclaim) {
flags &= ~BCH_WATERMARK_MASK;
flags |= BCH_WATERMARK_btree;
flags |= BCH_TRANS_COMMIT_journal_reclaim;
}

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

Expand Down
1 change: 0 additions & 1 deletion libbcachefs/buckets.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ int bch2_check_bucket_ref(struct btree_trans *trans,
bch2_data_type_str(ptr_data_type),
(printbuf_reset(&buf),
bch2_bkey_val_to_text(&buf, c, k), buf.buf));
BUG();
ret = -EIO;
goto err;
}
Expand Down
9 changes: 6 additions & 3 deletions libbcachefs/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ static struct bch_inode_info *bch2_inode_insert(struct bch_fs *c, struct bch_ino
BUG_ON(!old);

if (unlikely(old != inode)) {
discard_new_inode(&inode->v);
__destroy_inode(&inode->v);
kmem_cache_free(bch2_inode_cache, inode);
inode = old;
} else {
mutex_lock(&c->vfs_inodes_lock);
Expand Down Expand Up @@ -225,8 +226,10 @@ static struct bch_inode_info *bch2_new_inode(struct btree_trans *trans)

if (unlikely(!inode)) {
int ret = drop_locks_do(trans, (inode = to_bch_ei(new_inode(c->vfs_sb))) ? 0 : -ENOMEM);
if (ret && inode)
discard_new_inode(&inode->v);
if (ret && inode) {
__destroy_inode(&inode->v);
kmem_cache_free(bch2_inode_cache, inode);
}
if (ret)
return ERR_PTR(ret);
}
Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ int bch2_trigger_inode(struct btree_trans *trans,
struct bkey_s new,
unsigned flags)
{
s64 nr = bkey_is_inode(new.k) - bkey_is_inode(old.k);
s64 nr = (s64) bkey_is_inode(new.k) - (s64) bkey_is_inode(old.k);

if (flags & BTREE_TRIGGER_TRANSACTIONAL) {
if (nr) {
Expand Down
60 changes: 42 additions & 18 deletions libbcachefs/journal_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@ static void journal_write_endio(struct bio *bio)
percpu_ref_put(&ca->io_ref);
}

static CLOSURE_CALLBACK(do_journal_write)
static CLOSURE_CALLBACK(journal_write_submit)
{
closure_type(w, struct journal_buf, io);
struct journal *j = container_of(w, struct journal, buf[w->idx]);
Expand Down Expand Up @@ -1768,6 +1768,44 @@ static CLOSURE_CALLBACK(do_journal_write)
continue_at(cl, journal_write_done, j->wq);
}

static CLOSURE_CALLBACK(journal_write_preflush)
{
closure_type(w, struct journal_buf, io);
struct journal *j = container_of(w, struct journal, buf[w->idx]);
struct bch_fs *c = container_of(j, struct bch_fs, journal);

if (j->seq_ondisk + 1 != le64_to_cpu(w->data->seq)) {
spin_lock(&j->lock);
closure_wait(&j->async_wait, cl);
spin_unlock(&j->lock);

continue_at(cl, journal_write_preflush, j->wq);
return;
}

if (w->separate_flush) {
for_each_rw_member(c, ca) {
percpu_ref_get(&ca->io_ref);

struct journal_device *ja = &ca->journal;
struct bio *bio = &ja->bio[w->idx]->bio;
bio_reset(bio, ca->disk_sb.bdev,
REQ_OP_WRITE|REQ_SYNC|REQ_META|REQ_PREFLUSH);
bio->bi_end_io = journal_write_endio;
bio->bi_private = ca;
closure_bio_submit(bio, cl);
}

continue_at(cl, journal_write_submit, j->wq);
} else {
/*
* no need to punt to another work item if we're not waiting on
* preflushes
*/
journal_write_submit(&cl->work);
}
}

static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
{
struct bch_fs *c = container_of(j, struct bch_fs, journal);
Expand Down Expand Up @@ -2033,23 +2071,9 @@ CLOSURE_CALLBACK(bch2_journal_write)
goto err;

if (!JSET_NO_FLUSH(w->data))
closure_wait_event(&j->async_wait, j->seq_ondisk + 1 == le64_to_cpu(w->data->seq));

if (!JSET_NO_FLUSH(w->data) && w->separate_flush) {
for_each_rw_member(c, ca) {
percpu_ref_get(&ca->io_ref);

struct journal_device *ja = &ca->journal;
struct bio *bio = &ja->bio[w->idx]->bio;
bio_reset(bio, ca->disk_sb.bdev,
REQ_OP_WRITE|REQ_SYNC|REQ_META|REQ_PREFLUSH);
bio->bi_end_io = journal_write_endio;
bio->bi_private = ca;
closure_bio_submit(bio, cl);
}
}

continue_at(cl, do_journal_write, j->wq);
continue_at(cl, journal_write_preflush, j->wq);
else
continue_at(cl, journal_write_submit, j->wq);
return;
no_io:
continue_at(cl, journal_write_done, j->wq);
Expand Down
8 changes: 8 additions & 0 deletions libbcachefs/sb-clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ int bch2_sb_clean_validate_late(struct bch_fs *c, struct bch_sb_field_clean *cle
for (entry = clean->start;
entry < (struct jset_entry *) vstruct_end(&clean->field);
entry = vstruct_next(entry)) {
if (vstruct_end(entry) > vstruct_end(&clean->field)) {
bch_err(c, "journal entry (u64s %u) overran end of superblock clean section (u64s %u) by %zu",
le16_to_cpu(entry->u64s), le32_to_cpu(clean->field.u64s),
(u64 *) vstruct_end(entry) - (u64 *) vstruct_end(&clean->field));
bch2_sb_error_count(c, BCH_FSCK_ERR_sb_clean_entry_overrun);
return -BCH_ERR_fsck_repair_unimplemented;
}

ret = bch2_journal_entry_validate(c, NULL, entry,
le16_to_cpu(c->disk_sb.sb->version),
BCH_SB_BIG_ENDIAN(c->disk_sb.sb),
Expand Down
3 changes: 2 additions & 1 deletion libbcachefs/sb-errors_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@
x(btree_root_unreadable_and_scan_found_nothing, 263) \
x(snapshot_node_missing, 264) \
x(dup_backpointer_to_bad_csum_extent, 265) \
x(btree_bitmap_not_marked, 266)
x(btree_bitmap_not_marked, 266) \
x(sb_clean_entry_overrun, 267)

enum bch_sb_error_id {
#define x(t, n) BCH_FSCK_ERR_##t = n,
Expand Down
1 change: 1 addition & 0 deletions libbcachefs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ static void __bch2_fs_free(struct bch_fs *c)

bch2_find_btree_nodes_exit(&c->found_btree_nodes);
bch2_free_pending_node_rewrites(c);
bch2_fs_allocator_background_exit(c);
bch2_fs_sb_errors_exit(c);
bch2_fs_counters_exit(c);
bch2_fs_snapshots_exit(c);
Expand Down

0 comments on commit b9e48ed

Please sign in to comment.