Commit 21ad9dde authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Fix counting iterators for reflink pointers

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 64bc0011
...@@ -952,7 +952,7 @@ static int count_iters_for_insert(struct btree_trans *trans, ...@@ -952,7 +952,7 @@ static int count_iters_for_insert(struct btree_trans *trans,
if (*nr_iters >= max_iters) { if (*nr_iters >= max_iters) {
*end = bpos_min(*end, k.k->p); *end = bpos_min(*end, k.k->p);
return 0; ret = 1;
} }
break; break;
...@@ -973,11 +973,11 @@ static int count_iters_for_insert(struct btree_trans *trans, ...@@ -973,11 +973,11 @@ static int count_iters_for_insert(struct btree_trans *trans,
*nr_iters += 1; *nr_iters += 1;
if (overwrite && if (overwrite &&
k.k->type == KEY_TYPE_reflink_v) { r_k.k->type == KEY_TYPE_reflink_v) {
struct bkey_s_c_reflink_v r = bkey_s_c_to_reflink_v(k); struct bkey_s_c_reflink_v r = bkey_s_c_to_reflink_v(r_k);
if (le64_to_cpu(r.v->refcount) == 1) if (le64_to_cpu(r.v->refcount) == 1)
*nr_iters += bch2_bkey_nr_alloc_ptrs(k); *nr_iters += bch2_bkey_nr_alloc_ptrs(r_k);
} }
/* /*
...@@ -990,6 +990,7 @@ static int count_iters_for_insert(struct btree_trans *trans, ...@@ -990,6 +990,7 @@ static int count_iters_for_insert(struct btree_trans *trans,
pos.offset += r_k.k->p.offset - idx; pos.offset += r_k.k->p.offset - idx;
*end = bpos_min(*end, pos); *end = bpos_min(*end, pos);
ret = 1;
break; break;
} }
} }
...@@ -1002,6 +1003,8 @@ static int count_iters_for_insert(struct btree_trans *trans, ...@@ -1002,6 +1003,8 @@ static int count_iters_for_insert(struct btree_trans *trans,
return ret; return ret;
} }
#define EXTENT_ITERS_MAX (BTREE_ITER_MAX / 3)
int bch2_extent_atomic_end(struct btree_iter *iter, int bch2_extent_atomic_end(struct btree_iter *iter,
struct bkey_i *insert, struct bkey_i *insert,
struct bpos *end) struct bpos *end)
...@@ -1010,22 +1013,20 @@ int bch2_extent_atomic_end(struct btree_iter *iter, ...@@ -1010,22 +1013,20 @@ int bch2_extent_atomic_end(struct btree_iter *iter,
struct btree *b = iter->l[0].b; struct btree *b = iter->l[0].b;
struct btree_node_iter node_iter = iter->l[0].iter; struct btree_node_iter node_iter = iter->l[0].iter;
struct bkey_packed *_k; struct bkey_packed *_k;
unsigned nr_iters = unsigned nr_iters = 0;
bch2_bkey_nr_alloc_ptrs(bkey_i_to_s_c(insert)); int ret;
int ret = 0;
BUG_ON(iter->uptodate > BTREE_ITER_NEED_PEEK); BUG_ON(iter->uptodate > BTREE_ITER_NEED_PEEK);
BUG_ON(bkey_cmp(bkey_start_pos(&insert->k), b->data->min_key) < 0); BUG_ON(bkey_cmp(bkey_start_pos(&insert->k), b->data->min_key) < 0);
*end = bpos_min(insert->k.p, b->key.k.p); *end = bpos_min(insert->k.p, b->key.k.p);
ret = count_iters_for_insert(trans, bkey_i_to_s_c(insert), ret = count_iters_for_insert(trans, bkey_i_to_s_c(insert), 0, end,
0, end, &nr_iters, 10, false); &nr_iters, EXTENT_ITERS_MAX / 2, false);
if (ret) if (ret < 0)
return ret; return ret;
while (nr_iters < 20 && while ((_k = bch2_btree_node_iter_peek_filter(&node_iter, b,
(_k = bch2_btree_node_iter_peek_filter(&node_iter, b,
KEY_TYPE_discard))) { KEY_TYPE_discard))) {
struct bkey unpacked; struct bkey unpacked;
struct bkey_s_c k = bkey_disassemble(b, _k, &unpacked); struct bkey_s_c k = bkey_disassemble(b, _k, &unpacked);
...@@ -1039,18 +1040,15 @@ int bch2_extent_atomic_end(struct btree_iter *iter, ...@@ -1039,18 +1040,15 @@ int bch2_extent_atomic_end(struct btree_iter *iter,
offset = bkey_start_offset(&insert->k) - offset = bkey_start_offset(&insert->k) -
bkey_start_offset(k.k); bkey_start_offset(k.k);
ret = count_iters_for_insert(trans, k, offset, ret = count_iters_for_insert(trans, k, offset, end,
end, &nr_iters, 20, true); &nr_iters, EXTENT_ITERS_MAX, true);
if (ret) if (ret)
return ret;
if (nr_iters >= 20)
break; break;
bch2_btree_node_iter_advance(&node_iter, b); bch2_btree_node_iter_advance(&node_iter, b);
} }
return 0; return ret < 0 ? ret : 0;
} }
int bch2_extent_trim_atomic(struct bkey_i *k, struct btree_iter *iter) int bch2_extent_trim_atomic(struct bkey_i *k, struct btree_iter *iter)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment