Skip to content

Commit

Permalink
Update bcachefs sources to 938f680845d1 fixup! rename and export __ke…
Browse files Browse the repository at this point in the history
…rn_path_locked()
  • Loading branch information
Kent Overstreet committed Nov 16, 2023
1 parent cd43ee7 commit b68c54c
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 266 deletions.
2 changes: 1 addition & 1 deletion .bcachefs_revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3ca08ab51ec996180c20105489176b8c4327240c
938f680845d1be28979e23aee972dba010c464ba
108 changes: 48 additions & 60 deletions libbcachefs/backpointers.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,25 +457,18 @@ static int check_bp_exists(struct btree_trans *trans,
}

static int check_extent_to_backpointers(struct btree_trans *trans,
struct btree_iter *iter,
enum btree_id btree, unsigned level,
struct bpos bucket_start,
struct bpos bucket_end,
struct bpos_level *last_flushed)
struct bpos_level *last_flushed,
struct bkey_s_c k)
{
struct bch_fs *c = trans->c;
struct bkey_ptrs_c ptrs;
const union bch_extent_entry *entry;
struct extent_ptr_decoded p;
struct bkey_s_c k;
int ret;

k = bch2_btree_iter_peek_all_levels(iter);
ret = bkey_err(k);
if (ret)
return ret;
if (!k.k)
return 0;

ptrs = bch2_bkey_ptrs_c(k);
bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
struct bpos bucket_pos;
Expand All @@ -484,7 +477,7 @@ static int check_extent_to_backpointers(struct btree_trans *trans,
if (p.ptr.cached)
continue;

bch2_extent_ptr_to_bp(c, iter->btree_id, iter->path->level,
bch2_extent_ptr_to_bp(c, btree, level,
k, p, &bucket_pos, &bp);

ret = check_bp_exists(trans, bucket_pos, bp, k,
Expand All @@ -501,44 +494,33 @@ static int check_btree_root_to_backpointers(struct btree_trans *trans,
enum btree_id btree_id,
struct bpos bucket_start,
struct bpos bucket_end,
struct bpos_level *last_flushed)
struct bpos_level *last_flushed,
int *level)
{
struct bch_fs *c = trans->c;
struct btree_root *r = bch2_btree_id_root(c, btree_id);
struct btree_iter iter;
struct btree *b;
struct bkey_s_c k;
struct bkey_ptrs_c ptrs;
struct extent_ptr_decoded p;
const union bch_extent_entry *entry;
int ret;

bch2_trans_node_iter_init(trans, &iter, btree_id, POS_MIN, 0, r->level, 0);
retry:
bch2_trans_node_iter_init(trans, &iter, btree_id, POS_MIN,
0, bch2_btree_id_root(c, btree_id)->b->c.level, 0);
b = bch2_btree_iter_peek_node(&iter);
ret = PTR_ERR_OR_ZERO(b);
if (ret)
goto err;

BUG_ON(b != btree_node_root(c, b));

k = bkey_i_to_s_c(&b->key);
ptrs = bch2_bkey_ptrs_c(k);
bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
struct bpos bucket_pos;
struct bch_backpointer bp;

if (p.ptr.cached)
continue;
if (b != btree_node_root(c, b)) {
bch2_trans_iter_exit(trans, &iter);
goto retry;
}

bch2_extent_ptr_to_bp(c, iter.btree_id, b->c.level + 1,
k, p, &bucket_pos, &bp);
*level = b->c.level;

ret = check_bp_exists(trans, bucket_pos, bp, k,
k = bkey_i_to_s_c(&b->key);
ret = check_extent_to_backpointers(trans, btree_id, b->c.level + 1,
bucket_start, bucket_end,
last_flushed);
if (ret)
goto err;
}
last_flushed, k);
err:
bch2_trans_iter_exit(trans, &iter);
return ret;
Expand Down Expand Up @@ -616,43 +598,49 @@ static int bch2_check_extents_to_backpointers_pass(struct btree_trans *trans,
struct bch_fs *c = trans->c;
struct btree_iter iter;
enum btree_id btree_id;
struct bkey_s_c k;
struct bpos_level last_flushed = { UINT_MAX, POS_MIN };
int ret = 0;

for (btree_id = 0; btree_id < btree_id_nr_alive(c); btree_id++) {
unsigned depth = btree_type_has_ptrs(btree_id) ? 0 : 1;

bch2_trans_node_iter_init(trans, &iter, btree_id, POS_MIN, 0,
depth,
BTREE_ITER_ALL_LEVELS|
BTREE_ITER_PREFETCH);

do {
ret = commit_do(trans, NULL, NULL,
BCH_TRANS_COMMIT_lazy_rw|
BCH_TRANS_COMMIT_no_enospc,
check_extent_to_backpointers(trans, &iter,
bucket_start, bucket_end,
&last_flushed));
if (ret)
break;
} while (!bch2_btree_iter_advance(&iter));

bch2_trans_iter_exit(trans, &iter);

if (ret)
break;
int level, depth = btree_type_has_ptrs(btree_id) ? 0 : 1;

ret = commit_do(trans, NULL, NULL,
BCH_TRANS_COMMIT_lazy_rw|
BCH_TRANS_COMMIT_no_enospc,
check_btree_root_to_backpointers(trans, btree_id,
bucket_start, bucket_end,
&last_flushed));
&last_flushed, &level));
if (ret)
break;
return ret;

while (level >= depth) {
bch2_trans_node_iter_init(trans, &iter, btree_id, POS_MIN, 0,
level,
BTREE_ITER_PREFETCH);
for_each_btree_key_continue(trans, iter, BTREE_ITER_PREFETCH, k, ret) {
ret = commit_do(trans, NULL, NULL,
BCH_TRANS_COMMIT_lazy_rw|
BCH_TRANS_COMMIT_no_enospc,
check_extent_to_backpointers(trans, btree_id, level,
bucket_start, bucket_end,
&last_flushed, k));
if (ret)
break;

if (bpos_eq(iter.pos, SPOS_MAX))
break;
}
bch2_trans_iter_exit(trans, &iter);

if (ret)
return ret;

--level;
}
}
return ret;

return 0;
}

static struct bpos bucket_pos_to_bp_safe(const struct bch_fs *c,
Expand Down
123 changes: 8 additions & 115 deletions libbcachefs/btree_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1797,23 +1797,15 @@ struct btree *bch2_btree_iter_next_node(struct btree_iter *iter)

inline bool bch2_btree_iter_advance(struct btree_iter *iter)
{
if (likely(!(iter->flags & BTREE_ITER_ALL_LEVELS))) {
struct bpos pos = iter->k.p;
bool ret = !(iter->flags & BTREE_ITER_ALL_SNAPSHOTS
? bpos_eq(pos, SPOS_MAX)
: bkey_eq(pos, SPOS_MAX));

if (ret && !(iter->flags & BTREE_ITER_IS_EXTENTS))
pos = bkey_successor(iter, pos);
bch2_btree_iter_set_pos(iter, pos);
return ret;
} else {
if (!btree_path_node(iter->path, iter->path->level))
return true;
struct bpos pos = iter->k.p;
bool ret = !(iter->flags & BTREE_ITER_ALL_SNAPSHOTS
? bpos_eq(pos, SPOS_MAX)
: bkey_eq(pos, SPOS_MAX));

iter->advanced = true;
return false;
}
if (ret && !(iter->flags & BTREE_ITER_IS_EXTENTS))
pos = bkey_successor(iter, pos);
bch2_btree_iter_set_pos(iter, pos);
return ret;
}

inline bool bch2_btree_iter_rewind(struct btree_iter *iter)
Expand Down Expand Up @@ -2064,7 +2056,6 @@ struct bkey_s_c bch2_btree_iter_peek_upto(struct btree_iter *iter, struct bpos e
struct bpos iter_pos;
int ret;

EBUG_ON(iter->flags & BTREE_ITER_ALL_LEVELS);
EBUG_ON((iter->flags & BTREE_ITER_FILTER_SNAPSHOTS) && bkey_eq(end, POS_MAX));

if (iter->update_path) {
Expand Down Expand Up @@ -2190,103 +2181,6 @@ struct bkey_s_c bch2_btree_iter_peek_upto(struct btree_iter *iter, struct bpos e
goto out_no_locked;
}

/**
* bch2_btree_iter_peek_all_levels() - returns the first key greater than or
* equal to iterator's current position, returning keys from every level of the
* btree. For keys at different levels of the btree that compare equal, the key
* from the lower level (leaf) is returned first.
* @iter: iterator to peek from
*
* Returns: key if found, or an error extractable with bkey_err().
*/
struct bkey_s_c bch2_btree_iter_peek_all_levels(struct btree_iter *iter)
{
struct btree_trans *trans = iter->trans;
struct bkey_s_c k;
int ret;

EBUG_ON(iter->path->cached);
bch2_btree_iter_verify(iter);
BUG_ON(iter->path->level < iter->min_depth);
BUG_ON(!(iter->flags & BTREE_ITER_ALL_SNAPSHOTS));
EBUG_ON(!(iter->flags & BTREE_ITER_ALL_LEVELS));

while (1) {
iter->path = bch2_btree_path_set_pos(trans, iter->path, iter->pos,
iter->flags & BTREE_ITER_INTENT,
btree_iter_ip_allocated(iter));

ret = bch2_btree_path_traverse(trans, iter->path, iter->flags);
if (unlikely(ret)) {
/* ensure that iter->k is consistent with iter->pos: */
bch2_btree_iter_set_pos(iter, iter->pos);
k = bkey_s_c_err(ret);
goto out_no_locked;
}

/* Already at end? */
if (!btree_path_node(iter->path, iter->path->level)) {
k = bkey_s_c_null;
goto out_no_locked;
}

k = btree_path_level_peek_all(trans->c,
&iter->path->l[iter->path->level], &iter->k);

/* Check if we should go up to the parent node: */
if (!k.k ||
(iter->advanced &&
bpos_eq(path_l(iter->path)->b->key.k.p, iter->pos))) {
iter->pos = path_l(iter->path)->b->key.k.p;
btree_path_set_level_up(trans, iter->path);
iter->advanced = false;
continue;
}

/*
* Check if we should go back down to a leaf:
* If we're not in a leaf node, we only return the current key
* if it exactly matches iter->pos - otherwise we first have to
* go back to the leaf:
*/
if (iter->path->level != iter->min_depth &&
(iter->advanced ||
!k.k ||
!bpos_eq(iter->pos, k.k->p))) {
btree_path_set_level_down(trans, iter->path, iter->min_depth);
iter->pos = bpos_successor(iter->pos);
iter->advanced = false;
continue;
}

/* Check if we should go to the next key: */
if (iter->path->level == iter->min_depth &&
iter->advanced &&
k.k &&
bpos_eq(iter->pos, k.k->p)) {
iter->pos = bpos_successor(iter->pos);
iter->advanced = false;
continue;
}

if (iter->advanced &&
iter->path->level == iter->min_depth &&
!bpos_eq(k.k->p, iter->pos))
iter->advanced = false;

BUG_ON(iter->advanced);
BUG_ON(!k.k);
break;
}

iter->pos = k.k->p;
btree_path_set_should_be_locked(iter->path);
out_no_locked:
bch2_btree_iter_verify(iter);

return k;
}

/**
* bch2_btree_iter_next() - returns first key greater than iterator's current
* position
Expand Down Expand Up @@ -2453,7 +2347,6 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter)

bch2_btree_iter_verify(iter);
bch2_btree_iter_verify_entry_exit(iter);
EBUG_ON(iter->flags & BTREE_ITER_ALL_LEVELS);
EBUG_ON(iter->path->level && (iter->flags & BTREE_ITER_WITH_KEY_CACHE));

/* extents can't span inode numbers: */
Expand Down
10 changes: 1 addition & 9 deletions libbcachefs/btree_iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,6 @@ struct btree *bch2_btree_iter_next_node(struct btree_iter *);
struct bkey_s_c bch2_btree_iter_peek_upto(struct btree_iter *, struct bpos);
struct bkey_s_c bch2_btree_iter_next(struct btree_iter *);

struct bkey_s_c bch2_btree_iter_peek_all_levels(struct btree_iter *);

static inline struct bkey_s_c bch2_btree_iter_peek(struct btree_iter *iter)
{
return bch2_btree_iter_peek_upto(iter, SPOS_MAX);
Expand Down Expand Up @@ -408,9 +406,6 @@ static inline unsigned __bch2_btree_iter_flags(struct btree_trans *trans,
unsigned btree_id,
unsigned flags)
{
if (flags & BTREE_ITER_ALL_LEVELS)
flags |= BTREE_ITER_ALL_SNAPSHOTS|__BTREE_ITER_ALL_SNAPSHOTS;

if (!(flags & (BTREE_ITER_ALL_SNAPSHOTS|BTREE_ITER_NOT_EXTENTS)) &&
btree_id_is_extents(btree_id))
flags |= BTREE_ITER_IS_EXTENTS;
Expand Down Expand Up @@ -606,17 +601,14 @@ u32 bch2_trans_begin(struct btree_trans *);
static inline struct bkey_s_c bch2_btree_iter_peek_prev_type(struct btree_iter *iter,
unsigned flags)
{
BUG_ON(flags & BTREE_ITER_ALL_LEVELS);

return flags & BTREE_ITER_SLOTS ? bch2_btree_iter_peek_slot(iter) :
bch2_btree_iter_peek_prev(iter);
}

static inline struct bkey_s_c bch2_btree_iter_peek_type(struct btree_iter *iter,
unsigned flags)
{
return flags & BTREE_ITER_ALL_LEVELS ? bch2_btree_iter_peek_all_levels(iter) :
flags & BTREE_ITER_SLOTS ? bch2_btree_iter_peek_slot(iter) :
return flags & BTREE_ITER_SLOTS ? bch2_btree_iter_peek_slot(iter) :
bch2_btree_iter_peek(iter);
}

Expand Down
4 changes: 2 additions & 2 deletions libbcachefs/btree_locking.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ void __bch2_btree_path_downgrade(struct btree_trans *trans,
struct btree_path *path,
unsigned new_locks_want)
{
unsigned l;
unsigned l, old_locks_want = path->locks_want;

if (trans->restarted)
return;
Expand All @@ -689,7 +689,7 @@ void __bch2_btree_path_downgrade(struct btree_trans *trans,
bch2_btree_path_verify_locks(path);

path->downgrade_seq++;
trace_path_downgrade(trans, _RET_IP_, path);
trace_path_downgrade(trans, _RET_IP_, path, old_locks_want);
}

/* Btree transaction locking: */
Expand Down
Loading

0 comments on commit b68c54c

Please sign in to comment.