Commit 3eb26d01 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: bch2_trans_get_iter() no longer returns errors

Since we now always preallocate the maximum number of iterators when we
initialize a btree transaction, getting an iterator never fails - we can
delete a fair amount of error path code.

This patch also simplifies the iterator allocation code a bit.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent ec3d21a9
...@@ -346,7 +346,7 @@ void bch2_btree_trans_verify_locks(struct btree_trans *trans) ...@@ -346,7 +346,7 @@ void bch2_btree_trans_verify_locks(struct btree_trans *trans)
{ {
struct btree_iter *iter; struct btree_iter *iter;
trans_for_each_iter_all(trans, iter) trans_for_each_iter(trans, iter)
bch2_btree_iter_verify_locks(iter); bch2_btree_iter_verify_locks(iter);
} }
#else #else
...@@ -2002,110 +2002,37 @@ int bch2_trans_iter_free(struct btree_trans *trans, ...@@ -2002,110 +2002,37 @@ int bch2_trans_iter_free(struct btree_trans *trans,
return bch2_trans_iter_put(trans, iter); return bch2_trans_iter_put(trans, iter);
} }
#if 0 noinline __cold
static int bch2_trans_realloc_iters(struct btree_trans *trans, static void btree_trans_iter_alloc_fail(struct btree_trans *trans)
unsigned new_size)
{ {
void *p, *new_iters, *new_updates, *new_updates2;
size_t iters_bytes;
size_t updates_bytes;
new_size = roundup_pow_of_two(new_size);
BUG_ON(new_size > BTREE_ITER_MAX);
if (new_size <= trans->size)
return 0;
BUG_ON(trans->used_mempool);
bch2_trans_unlock(trans);
iters_bytes = sizeof(struct btree_iter) * new_size; struct btree_iter *iter;
updates_bytes = sizeof(struct btree_insert_entry) * new_size;
p = kmalloc(iters_bytes +
updates_bytes +
updates_bytes, GFP_NOFS);
if (p)
goto success;
p = mempool_alloc(&trans->c->btree_iters_pool, GFP_NOFS);
new_size = BTREE_ITER_MAX;
trans->used_mempool = true;
success:
new_iters = p; p += iters_bytes;
new_updates = p; p += updates_bytes;
new_updates2 = p; p += updates_bytes;
memcpy(new_iters, trans->iters,
sizeof(struct btree_iter) * trans->nr_iters);
memcpy(new_updates, trans->updates,
sizeof(struct btree_insert_entry) * trans->nr_updates);
memcpy(new_updates2, trans->updates2,
sizeof(struct btree_insert_entry) * trans->nr_updates2);
if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG))
memset(trans->iters, POISON_FREE,
sizeof(struct btree_iter) * trans->nr_iters +
sizeof(struct btree_insert_entry) * trans->nr_iters);
kfree(trans->iters);
trans->iters = new_iters;
trans->updates = new_updates;
trans->updates2 = new_updates2;
trans->size = new_size;
if (trans->iters_live) {
trace_trans_restart_iters_realloced(trans->ip, trans->size);
return -EINTR;
}
return 0; trans_for_each_iter(trans, iter)
pr_err("iter: btree %s pos %llu:%llu%s%s%s %ps",
bch2_btree_ids[iter->btree_id],
iter->pos.inode,
iter->pos.offset,
(trans->iters_live & (1ULL << iter->idx)) ? " live" : "",
(trans->iters_touched & (1ULL << iter->idx)) ? " touched" : "",
iter->flags & BTREE_ITER_KEEP_UNTIL_COMMIT ? " keep" : "",
(void *) iter->ip_allocated);
panic("trans iter oveflow\n");
} }
#endif
static struct btree_iter *btree_trans_iter_alloc(struct btree_trans *trans) static struct btree_iter *btree_trans_iter_alloc(struct btree_trans *trans)
{ {
unsigned idx = __ffs64(~trans->iters_linked); unsigned idx;
if (idx < trans->nr_iters)
goto got_slot;
if (trans->nr_iters == trans->size) {
struct btree_iter *iter;
BUG_ON(trans->size < BTREE_ITER_MAX);
trans_for_each_iter(trans, iter) {
pr_err("iter: btree %s pos %llu:%llu%s%s%s %ps",
bch2_btree_ids[iter->btree_id],
iter->pos.inode,
iter->pos.offset,
(trans->iters_live & (1ULL << iter->idx)) ? " live" : "",
(trans->iters_touched & (1ULL << iter->idx)) ? " touched" : "",
iter->flags & BTREE_ITER_KEEP_UNTIL_COMMIT ? " keep" : "",
(void *) iter->ip_allocated);
}
panic("trans iter oveflow\n"); if (unlikely(trans->iters_linked ==
#if 0 ~((~0ULL << 1) << (BTREE_ITER_MAX - 1))))
ret = bch2_trans_realloc_iters(trans, trans->size * 2); btree_trans_iter_alloc_fail(trans);
if (ret)
return ERR_PTR(ret);
#endif
}
idx = trans->nr_iters++; idx = __ffs64(~trans->iters_linked);
BUG_ON(trans->nr_iters > trans->size);
trans->iters[idx].idx = idx; trans->iters_linked |= 1ULL << idx;
got_slot: trans->iters[idx].idx = idx;
BUG_ON(trans->iters_linked & (1ULL << idx)); trans->iters[idx].flags = 0;
trans->iters_linked |= 1ULL << idx;
trans->iters[idx].flags = 0;
return &trans->iters[idx]; return &trans->iters[idx];
} }
...@@ -2141,8 +2068,6 @@ static struct btree_iter *__btree_trans_get_iter(struct btree_trans *trans, ...@@ -2141,8 +2068,6 @@ static struct btree_iter *__btree_trans_get_iter(struct btree_trans *trans,
{ {
struct btree_iter *iter, *best = NULL; struct btree_iter *iter, *best = NULL;
BUG_ON(trans->nr_iters > BTREE_ITER_MAX);
trans_for_each_iter(trans, iter) { trans_for_each_iter(trans, iter) {
if (btree_iter_type(iter) != (flags & BTREE_ITER_TYPE)) if (btree_iter_type(iter) != (flags & BTREE_ITER_TYPE))
continue; continue;
...@@ -2160,16 +2085,10 @@ static struct btree_iter *__btree_trans_get_iter(struct btree_trans *trans, ...@@ -2160,16 +2085,10 @@ static struct btree_iter *__btree_trans_get_iter(struct btree_trans *trans,
if (!best) { if (!best) {
iter = btree_trans_iter_alloc(trans); iter = btree_trans_iter_alloc(trans);
if (IS_ERR(iter))
return iter;
bch2_btree_iter_init(trans, iter, btree_id, pos, flags); bch2_btree_iter_init(trans, iter, btree_id, pos, flags);
} else if ((trans->iters_live & (1ULL << best->idx)) || } else if ((trans->iters_live & (1ULL << best->idx)) ||
(best->flags & BTREE_ITER_KEEP_UNTIL_COMMIT)) { (best->flags & BTREE_ITER_KEEP_UNTIL_COMMIT)) {
iter = btree_trans_iter_alloc(trans); iter = btree_trans_iter_alloc(trans);
if (IS_ERR(iter))
return iter;
btree_iter_copy(iter, best); btree_iter_copy(iter, best);
} else { } else {
iter = best; iter = best;
...@@ -2203,9 +2122,8 @@ struct btree_iter *__bch2_trans_get_iter(struct btree_trans *trans, ...@@ -2203,9 +2122,8 @@ struct btree_iter *__bch2_trans_get_iter(struct btree_trans *trans,
struct btree_iter *iter = struct btree_iter *iter =
__btree_trans_get_iter(trans, btree_id, pos, flags); __btree_trans_get_iter(trans, btree_id, pos, flags);
if (!IS_ERR(iter)) __bch2_btree_iter_set_pos(iter, pos,
__bch2_btree_iter_set_pos(iter, pos, btree_node_type_is_extents(btree_id));
btree_node_type_is_extents(btree_id));
return iter; return iter;
} }
...@@ -2221,7 +2139,6 @@ struct btree_iter *bch2_trans_get_node_iter(struct btree_trans *trans, ...@@ -2221,7 +2139,6 @@ struct btree_iter *bch2_trans_get_node_iter(struct btree_trans *trans,
flags|BTREE_ITER_NODES); flags|BTREE_ITER_NODES);
unsigned i; unsigned i;
BUG_ON(IS_ERR(iter));
BUG_ON(bkey_cmp(iter->pos, pos)); BUG_ON(bkey_cmp(iter->pos, pos));
iter->locks_want = locks_want; iter->locks_want = locks_want;
...@@ -2241,9 +2158,6 @@ struct btree_iter *__bch2_trans_copy_iter(struct btree_trans *trans, ...@@ -2241,9 +2158,6 @@ struct btree_iter *__bch2_trans_copy_iter(struct btree_trans *trans,
struct btree_iter *iter; struct btree_iter *iter;
iter = btree_trans_iter_alloc(trans); iter = btree_trans_iter_alloc(trans);
if (IS_ERR(iter))
return iter;
btree_iter_copy(iter, src); btree_iter_copy(iter, src);
trans->iters_live |= 1ULL << iter->idx; trans->iters_live |= 1ULL << iter->idx;
...@@ -2318,7 +2232,6 @@ void bch2_trans_reset(struct btree_trans *trans, unsigned flags) ...@@ -2318,7 +2232,6 @@ void bch2_trans_reset(struct btree_trans *trans, unsigned flags)
trans->iters_touched &= trans->iters_live; trans->iters_touched &= trans->iters_live;
trans->need_reset = 0;
trans->nr_updates = 0; trans->nr_updates = 0;
trans->nr_updates2 = 0; trans->nr_updates2 = 0;
trans->mem_top = 0; trans->mem_top = 0;
...@@ -2340,9 +2253,8 @@ void bch2_trans_reset(struct btree_trans *trans, unsigned flags) ...@@ -2340,9 +2253,8 @@ void bch2_trans_reset(struct btree_trans *trans, unsigned flags)
static void bch2_trans_alloc_iters(struct btree_trans *trans, struct bch_fs *c) static void bch2_trans_alloc_iters(struct btree_trans *trans, struct bch_fs *c)
{ {
unsigned new_size = BTREE_ITER_MAX; size_t iters_bytes = sizeof(struct btree_iter) * BTREE_ITER_MAX;
size_t iters_bytes = sizeof(struct btree_iter) * new_size; size_t updates_bytes = sizeof(struct btree_insert_entry) * BTREE_ITER_MAX;
size_t updates_bytes = sizeof(struct btree_insert_entry) * new_size;
void *p = NULL; void *p = NULL;
BUG_ON(trans->used_mempool); BUG_ON(trans->used_mempool);
...@@ -2356,7 +2268,6 @@ static void bch2_trans_alloc_iters(struct btree_trans *trans, struct bch_fs *c) ...@@ -2356,7 +2268,6 @@ static void bch2_trans_alloc_iters(struct btree_trans *trans, struct bch_fs *c)
trans->iters = p; p += iters_bytes; trans->iters = p; p += iters_bytes;
trans->updates = p; p += updates_bytes; trans->updates = p; p += updates_bytes;
trans->updates2 = p; p += updates_bytes; trans->updates2 = p; p += updates_bytes;
trans->size = new_size;
} }
void bch2_trans_init(struct btree_trans *trans, struct bch_fs *c, void bch2_trans_init(struct btree_trans *trans, struct bch_fs *c,
......
...@@ -48,21 +48,16 @@ static inline int btree_iter_err(const struct btree_iter *iter) ...@@ -48,21 +48,16 @@ static inline int btree_iter_err(const struct btree_iter *iter)
/* Iterate over iters within a transaction: */ /* Iterate over iters within a transaction: */
#define trans_for_each_iter_all(_trans, _iter) \
for (_iter = (_trans)->iters; \
_iter < (_trans)->iters + (_trans)->nr_iters; \
_iter++)
static inline struct btree_iter * static inline struct btree_iter *
__trans_next_iter(struct btree_trans *trans, unsigned idx) __trans_next_iter(struct btree_trans *trans, unsigned idx)
{ {
EBUG_ON(idx < trans->nr_iters && trans->iters[idx].idx != idx); u64 l = trans->iters_linked >> idx;
if (!l)
for (; idx < trans->nr_iters; idx++) return NULL;
if (trans->iters_linked & (1ULL << idx))
return &trans->iters[idx];
return NULL; idx += __ffs64(l);
EBUG_ON(trans->iters[idx].idx != idx);
return &trans->iters[idx];
} }
#define trans_for_each_iter(_trans, _iter) \ #define trans_for_each_iter(_trans, _iter) \
...@@ -240,10 +235,9 @@ static inline int bkey_err(struct bkey_s_c k) ...@@ -240,10 +235,9 @@ static inline int bkey_err(struct bkey_s_c k)
#define for_each_btree_key(_trans, _iter, _btree_id, \ #define for_each_btree_key(_trans, _iter, _btree_id, \
_start, _flags, _k, _ret) \ _start, _flags, _k, _ret) \
for ((_ret) = PTR_ERR_OR_ZERO((_iter) = \ for ((_iter) = bch2_trans_get_iter((_trans), (_btree_id), \
bch2_trans_get_iter((_trans), (_btree_id), \ (_start), (_flags)), \
(_start), (_flags))) ?: \ (_ret) = PTR_ERR_OR_ZERO(((_k) = \
PTR_ERR_OR_ZERO(((_k) = \
__bch2_btree_iter_peek(_iter, _flags)).k); \ __bch2_btree_iter_peek(_iter, _flags)).k); \
!_ret && (_k).k; \ !_ret && (_k).k; \
(_ret) = PTR_ERR_OR_ZERO(((_k) = \ (_ret) = PTR_ERR_OR_ZERO(((_k) = \
...@@ -270,9 +264,7 @@ bch2_trans_get_iter(struct btree_trans *trans, enum btree_id btree_id, ...@@ -270,9 +264,7 @@ bch2_trans_get_iter(struct btree_trans *trans, enum btree_id btree_id,
{ {
struct btree_iter *iter = struct btree_iter *iter =
__bch2_trans_get_iter(trans, btree_id, pos, flags); __bch2_trans_get_iter(trans, btree_id, pos, flags);
iter->ip_allocated = _THIS_IP_;
if (!IS_ERR(iter))
iter->ip_allocated = _THIS_IP_;
return iter; return iter;
} }
...@@ -284,10 +276,8 @@ bch2_trans_copy_iter(struct btree_trans *trans, struct btree_iter *src) ...@@ -284,10 +276,8 @@ bch2_trans_copy_iter(struct btree_trans *trans, struct btree_iter *src)
struct btree_iter *iter = struct btree_iter *iter =
__bch2_trans_copy_iter(trans, src); __bch2_trans_copy_iter(trans, src);
if (!IS_ERR(iter)) iter->ip_allocated = _THIS_IP_;
iter->ip_allocated = _THIS_IP_;
return iter; return iter;
} }
struct btree_iter *bch2_trans_get_node_iter(struct btree_trans *, struct btree_iter *bch2_trans_get_node_iter(struct btree_trans *,
......
...@@ -170,9 +170,6 @@ static int btree_key_cache_fill(struct btree_trans *trans, ...@@ -170,9 +170,6 @@ static int btree_key_cache_fill(struct btree_trans *trans,
iter = bch2_trans_get_iter(trans, ck->key.btree_id, iter = bch2_trans_get_iter(trans, ck->key.btree_id,
ck->key.pos, BTREE_ITER_SLOTS); ck->key.pos, BTREE_ITER_SLOTS);
if (IS_ERR(iter))
return PTR_ERR(iter);
k = bch2_btree_iter_peek_slot(iter); k = bch2_btree_iter_peek_slot(iter);
ret = bkey_err(k); ret = bkey_err(k);
if (ret) { if (ret) {
...@@ -326,18 +323,11 @@ static int btree_key_cache_flush_pos(struct btree_trans *trans, ...@@ -326,18 +323,11 @@ static int btree_key_cache_flush_pos(struct btree_trans *trans,
b_iter = bch2_trans_get_iter(trans, key.btree_id, key.pos, b_iter = bch2_trans_get_iter(trans, key.btree_id, key.pos,
BTREE_ITER_SLOTS| BTREE_ITER_SLOTS|
BTREE_ITER_INTENT); BTREE_ITER_INTENT);
ret = PTR_ERR_OR_ZERO(b_iter);
if (ret)
goto out;
c_iter = bch2_trans_get_iter(trans, key.btree_id, key.pos, c_iter = bch2_trans_get_iter(trans, key.btree_id, key.pos,
BTREE_ITER_CACHED| BTREE_ITER_CACHED|
BTREE_ITER_CACHED_NOFILL| BTREE_ITER_CACHED_NOFILL|
BTREE_ITER_CACHED_NOCREATE| BTREE_ITER_CACHED_NOCREATE|
BTREE_ITER_INTENT); BTREE_ITER_INTENT);
ret = PTR_ERR_OR_ZERO(c_iter);
if (ret)
goto out;
retry: retry:
ret = bch2_btree_iter_traverse(c_iter); ret = bch2_btree_iter_traverse(c_iter);
if (ret) if (ret)
......
...@@ -357,20 +357,17 @@ struct btree_trans { ...@@ -357,20 +357,17 @@ struct btree_trans {
unsigned long ip; unsigned long ip;
int srcu_idx; int srcu_idx;
u64 iters_linked;
u64 iters_live;
u64 iters_touched;
u8 nr_iters;
u8 nr_updates; u8 nr_updates;
u8 nr_updates2; u8 nr_updates2;
u8 size;
unsigned used_mempool:1; unsigned used_mempool:1;
unsigned error:1; unsigned error:1;
unsigned nounlock:1; unsigned nounlock:1;
unsigned need_reset:1;
unsigned in_traverse_all:1; unsigned in_traverse_all:1;
u64 iters_linked;
u64 iters_live;
u64 iters_touched;
unsigned mem_top; unsigned mem_top;
unsigned mem_bytes; unsigned mem_bytes;
void *mem; void *mem;
......
...@@ -717,7 +717,7 @@ static void bch2_trans_update2(struct btree_trans *trans, ...@@ -717,7 +717,7 @@ static void bch2_trans_update2(struct btree_trans *trans,
BUG_ON(iter->uptodate > BTREE_ITER_NEED_PEEK); BUG_ON(iter->uptodate > BTREE_ITER_NEED_PEEK);
EBUG_ON(trans->nr_updates2 >= trans->nr_iters); EBUG_ON(trans->nr_updates2 >= BTREE_ITER_MAX);
iter->flags |= BTREE_ITER_KEEP_UNTIL_COMMIT; iter->flags |= BTREE_ITER_KEEP_UNTIL_COMMIT;
...@@ -750,8 +750,6 @@ static int extent_update_to_keys(struct btree_trans *trans, ...@@ -750,8 +750,6 @@ static int extent_update_to_keys(struct btree_trans *trans,
return 0; return 0;
iter = bch2_trans_copy_iter(trans, orig_iter); iter = bch2_trans_copy_iter(trans, orig_iter);
if (IS_ERR(iter))
return PTR_ERR(iter);
iter->flags |= BTREE_ITER_INTENT; iter->flags |= BTREE_ITER_INTENT;
__bch2_btree_iter_set_pos(iter, insert->k.p, false); __bch2_btree_iter_set_pos(iter, insert->k.p, false);
...@@ -770,10 +768,6 @@ static int extent_handle_overwrites(struct btree_trans *trans, ...@@ -770,10 +768,6 @@ static int extent_handle_overwrites(struct btree_trans *trans,
int ret = 0; int ret = 0;
iter = bch2_trans_get_iter(trans, btree_id, start, BTREE_ITER_INTENT); iter = bch2_trans_get_iter(trans, btree_id, start, BTREE_ITER_INTENT);
ret = PTR_ERR_OR_ZERO(iter);
if (ret)
return ret;
k = bch2_btree_iter_peek_with_updates(iter); k = bch2_btree_iter_peek_with_updates(iter);
while (k.k && !(ret = bkey_err(k))) { while (k.k && !(ret = bkey_err(k))) {
...@@ -782,8 +776,6 @@ static int extent_handle_overwrites(struct btree_trans *trans, ...@@ -782,8 +776,6 @@ static int extent_handle_overwrites(struct btree_trans *trans,
if (bkey_cmp(bkey_start_pos(k.k), start) < 0) { if (bkey_cmp(bkey_start_pos(k.k), start) < 0) {
update_iter = bch2_trans_copy_iter(trans, iter); update_iter = bch2_trans_copy_iter(trans, iter);
if ((ret = PTR_ERR_OR_ZERO(update_iter)))
goto err;
update = bch2_trans_kmalloc(trans, bkey_bytes(k.k)); update = bch2_trans_kmalloc(trans, bkey_bytes(k.k));
if ((ret = PTR_ERR_OR_ZERO(update))) if ((ret = PTR_ERR_OR_ZERO(update)))
...@@ -799,8 +791,6 @@ static int extent_handle_overwrites(struct btree_trans *trans, ...@@ -799,8 +791,6 @@ static int extent_handle_overwrites(struct btree_trans *trans,
if (bkey_cmp(k.k->p, end) > 0) { if (bkey_cmp(k.k->p, end) > 0) {
update_iter = bch2_trans_copy_iter(trans, iter); update_iter = bch2_trans_copy_iter(trans, iter);
if ((ret = PTR_ERR_OR_ZERO(update_iter)))
goto err;
update = bch2_trans_kmalloc(trans, bkey_bytes(k.k)); update = bch2_trans_kmalloc(trans, bkey_bytes(k.k));
if ((ret = PTR_ERR_OR_ZERO(update))) if ((ret = PTR_ERR_OR_ZERO(update)))
...@@ -814,8 +804,6 @@ static int extent_handle_overwrites(struct btree_trans *trans, ...@@ -814,8 +804,6 @@ static int extent_handle_overwrites(struct btree_trans *trans,
bch2_trans_iter_put(trans, update_iter); bch2_trans_iter_put(trans, update_iter);
} else { } else {
update_iter = bch2_trans_copy_iter(trans, iter); update_iter = bch2_trans_copy_iter(trans, iter);
if ((ret = PTR_ERR_OR_ZERO(update_iter)))
goto err;
update = bch2_trans_kmalloc(trans, sizeof(struct bkey)); update = bch2_trans_kmalloc(trans, sizeof(struct bkey));
if ((ret = PTR_ERR_OR_ZERO(update))) if ((ret = PTR_ERR_OR_ZERO(update)))
...@@ -847,8 +835,6 @@ int __bch2_trans_commit(struct btree_trans *trans) ...@@ -847,8 +835,6 @@ int __bch2_trans_commit(struct btree_trans *trans)
unsigned u64s; unsigned u64s;
int ret = 0; int ret = 0;
BUG_ON(trans->need_reset);
if (!trans->nr_updates) if (!trans->nr_updates)
goto out_noupdates; goto out_noupdates;
...@@ -1041,10 +1027,6 @@ int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter, ...@@ -1041,10 +1027,6 @@ int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter,
*/ */
if (trans->iters_live & (1ULL << i->iter->idx)) { if (trans->iters_live & (1ULL << i->iter->idx)) {
i->iter = bch2_trans_copy_iter(trans, i->iter); i->iter = bch2_trans_copy_iter(trans, i->iter);
if (IS_ERR(i->iter)) {
trans->need_reset = true;
return PTR_ERR(i->iter);
}
i->iter->flags |= BTREE_ITER_KEEP_UNTIL_COMMIT; i->iter->flags |= BTREE_ITER_KEEP_UNTIL_COMMIT;
bch2_trans_iter_put(trans, i->iter); bch2_trans_iter_put(trans, i->iter);
...@@ -1054,7 +1036,7 @@ int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter, ...@@ -1054,7 +1036,7 @@ int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter,
bch2_btree_iter_set_pos(i->iter, n.k->k.p); bch2_btree_iter_set_pos(i->iter, n.k->k.p);
} }
EBUG_ON(trans->nr_updates >= trans->nr_iters); EBUG_ON(trans->nr_updates >= BTREE_ITER_MAX);
array_insert_item(trans->updates, trans->nr_updates, array_insert_item(trans->updates, trans->nr_updates,
i - trans->updates, n); i - trans->updates, n);
...@@ -1069,8 +1051,6 @@ int __bch2_btree_insert(struct btree_trans *trans, ...@@ -1069,8 +1051,6 @@ int __bch2_btree_insert(struct btree_trans *trans,
iter = bch2_trans_get_iter(trans, id, bkey_start_pos(&k->k), iter = bch2_trans_get_iter(trans, id, bkey_start_pos(&k->k),
BTREE_ITER_INTENT); BTREE_ITER_INTENT);
if (IS_ERR(iter))
return PTR_ERR(iter);
ret = bch2_btree_iter_traverse(iter) ?: ret = bch2_btree_iter_traverse(iter) ?:
bch2_trans_update(trans, iter, k, 0); bch2_trans_update(trans, iter, k, 0);
...@@ -1117,9 +1097,6 @@ int bch2_btree_delete_range_trans(struct btree_trans *trans, enum btree_id id, ...@@ -1117,9 +1097,6 @@ int bch2_btree_delete_range_trans(struct btree_trans *trans, enum btree_id id,
int ret = 0; int ret = 0;
iter = bch2_trans_get_iter(trans, id, start, BTREE_ITER_INTENT); iter = bch2_trans_get_iter(trans, id, start, BTREE_ITER_INTENT);
ret = PTR_ERR_OR_ZERO(iter);
if (ret)
return ret;
retry: retry:
while ((k = bch2_btree_iter_peek(iter)).k && while ((k = bch2_btree_iter_peek(iter)).k &&
!(ret = bkey_err(k)) && !(ret = bkey_err(k)) &&
......
...@@ -1575,9 +1575,6 @@ static int trans_get_key(struct btree_trans *trans, ...@@ -1575,9 +1575,6 @@ static int trans_get_key(struct btree_trans *trans,
*iter = bch2_trans_get_iter(trans, btree_id, pos, *iter = bch2_trans_get_iter(trans, btree_id, pos,
flags|BTREE_ITER_INTENT); flags|BTREE_ITER_INTENT);
if (IS_ERR(*iter))
return PTR_ERR(*iter);
*k = __bch2_btree_iter_peek(*iter, flags); *k = __bch2_btree_iter_peek(*iter, flags);
ret = bkey_err(*k); ret = bkey_err(*k);
if (ret) if (ret)
...@@ -1605,9 +1602,6 @@ static int bch2_trans_start_alloc_update(struct btree_trans *trans, struct btree ...@@ -1605,9 +1602,6 @@ static int bch2_trans_start_alloc_update(struct btree_trans *trans, struct btree
BTREE_ITER_CACHED| BTREE_ITER_CACHED|
BTREE_ITER_CACHED_NOFILL| BTREE_ITER_CACHED_NOFILL|
BTREE_ITER_INTENT); BTREE_ITER_INTENT);
if (IS_ERR(iter))
return PTR_ERR(iter);
ret = bch2_btree_iter_traverse(iter); ret = bch2_btree_iter_traverse(iter);
if (ret) { if (ret) {
bch2_trans_iter_put(trans, iter); bch2_trans_iter_put(trans, iter);
......
...@@ -2489,10 +2489,7 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode, ...@@ -2489,10 +2489,7 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode,
src = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS, src = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS,
POS(inode->v.i_ino, src_start >> 9), POS(inode->v.i_ino, src_start >> 9),
BTREE_ITER_INTENT); BTREE_ITER_INTENT);
BUG_ON(IS_ERR_OR_NULL(src));
dst = bch2_trans_copy_iter(&trans, src); dst = bch2_trans_copy_iter(&trans, src);
BUG_ON(IS_ERR_OR_NULL(dst));
while (1) { while (1) {
struct disk_reservation disk_res = struct disk_reservation disk_res =
......
...@@ -230,7 +230,6 @@ static int hash_check_duplicates(struct btree_trans *trans, ...@@ -230,7 +230,6 @@ static int hash_check_duplicates(struct btree_trans *trans,
return 0; return 0;
iter = bch2_trans_copy_iter(trans, h->chain); iter = bch2_trans_copy_iter(trans, h->chain);
BUG_ON(IS_ERR(iter));
for_each_btree_key_continue(iter, 0, k2, ret) { for_each_btree_key_continue(iter, 0, k2, ret) {
if (bkey_cmp(k2.k->p, k.k->p) >= 0) if (bkey_cmp(k2.k->p, k.k->p) >= 0)
...@@ -265,10 +264,8 @@ static void hash_set_chain_start(struct btree_trans *trans, ...@@ -265,10 +264,8 @@ static void hash_set_chain_start(struct btree_trans *trans,
hash_stop_chain(trans, h); hash_stop_chain(trans, h);
if (!hole) { if (!hole) {
if (!h->chain) { if (!h->chain)
h->chain = bch2_trans_copy_iter(trans, k_iter); h->chain = bch2_trans_copy_iter(trans, k_iter);
BUG_ON(IS_ERR(h->chain));
}
h->chain_end = k.k->p.offset; h->chain_end = k.k->p.offset;
} }
...@@ -440,9 +437,6 @@ static int bch2_fix_overlapping_extent(struct btree_trans *trans, ...@@ -440,9 +437,6 @@ static int bch2_fix_overlapping_extent(struct btree_trans *trans,
bch2_cut_front(cut_at, u); bch2_cut_front(cut_at, u);
u_iter = bch2_trans_copy_iter(trans, iter); u_iter = bch2_trans_copy_iter(trans, iter);
ret = PTR_ERR_OR_ZERO(u_iter);
if (ret)
return ret;
/* /*
* We don't want to go through the * We don't want to go through the
......
...@@ -302,9 +302,6 @@ struct btree_iter *bch2_inode_peek(struct btree_trans *trans, ...@@ -302,9 +302,6 @@ struct btree_iter *bch2_inode_peek(struct btree_trans *trans,
iter = bch2_trans_get_iter(trans, BTREE_ID_INODES, POS(0, inum), iter = bch2_trans_get_iter(trans, BTREE_ID_INODES, POS(0, inum),
BTREE_ITER_CACHED|flags); BTREE_ITER_CACHED|flags);
if (IS_ERR(iter))
return iter;
k = bch2_btree_iter_peek_cached(iter); k = bch2_btree_iter_peek_cached(iter);
ret = bkey_err(k); ret = bkey_err(k);
if (ret) if (ret)
...@@ -640,9 +637,6 @@ int bch2_inode_find_by_inum_trans(struct btree_trans *trans, u64 inode_nr, ...@@ -640,9 +637,6 @@ int bch2_inode_find_by_inum_trans(struct btree_trans *trans, u64 inode_nr,
iter = bch2_trans_get_iter(trans, BTREE_ID_INODES, iter = bch2_trans_get_iter(trans, BTREE_ID_INODES,
POS(0, inode_nr), BTREE_ITER_CACHED); POS(0, inode_nr), BTREE_ITER_CACHED);
if (IS_ERR(iter))
return PTR_ERR(iter);
k = bch2_btree_iter_peek_cached(iter); k = bch2_btree_iter_peek_cached(iter);
ret = bkey_err(k); ret = bkey_err(k);
if (ret) if (ret)
......
...@@ -207,8 +207,6 @@ static int sum_sector_overwrites(struct btree_trans *trans, ...@@ -207,8 +207,6 @@ static int sum_sector_overwrites(struct btree_trans *trans,
*delta = 0; *delta = 0;
iter = bch2_trans_copy_iter(trans, extent_iter); iter = bch2_trans_copy_iter(trans, extent_iter);
if (IS_ERR(iter))
return PTR_ERR(iter);
for_each_btree_key_continue(iter, BTREE_ITER_SLOTS, old, ret) { for_each_btree_key_continue(iter, BTREE_ITER_SLOTS, old, ret) {
if (!may_allocate && if (!may_allocate &&
...@@ -1781,9 +1779,6 @@ static int __bch2_rbio_narrow_crcs(struct btree_trans *trans, ...@@ -1781,9 +1779,6 @@ static int __bch2_rbio_narrow_crcs(struct btree_trans *trans,
iter = bch2_trans_get_iter(trans, BTREE_ID_EXTENTS, rbio->pos, iter = bch2_trans_get_iter(trans, BTREE_ID_EXTENTS, rbio->pos,
BTREE_ITER_SLOTS|BTREE_ITER_INTENT); BTREE_ITER_SLOTS|BTREE_ITER_INTENT);
if ((ret = PTR_ERR_OR_ZERO(iter)))
goto out;
k = bch2_btree_iter_peek_slot(iter); k = bch2_btree_iter_peek_slot(iter);
if ((ret = bkey_err(k))) if ((ret = bkey_err(k)))
goto out; goto out;
...@@ -1991,10 +1986,6 @@ int __bch2_read_indirect_extent(struct btree_trans *trans, ...@@ -1991,10 +1986,6 @@ int __bch2_read_indirect_extent(struct btree_trans *trans,
iter = bch2_trans_get_iter(trans, BTREE_ID_REFLINK, iter = bch2_trans_get_iter(trans, BTREE_ID_REFLINK,
POS(0, reflink_offset), POS(0, reflink_offset),
BTREE_ITER_SLOTS); BTREE_ITER_SLOTS);
ret = PTR_ERR_OR_ZERO(iter);
if (ret)
return ret;
k = bch2_btree_iter_peek_slot(iter); k = bch2_btree_iter_peek_slot(iter);
ret = bkey_err(k); ret = bkey_err(k);
if (ret) if (ret)
......
...@@ -443,9 +443,6 @@ static int bch2_extent_replay_key(struct bch_fs *c, enum btree_id btree_id, ...@@ -443,9 +443,6 @@ static int bch2_extent_replay_key(struct bch_fs *c, enum btree_id btree_id,
bch2_cut_back(atomic_end, split); bch2_cut_back(atomic_end, split);
split_iter = bch2_trans_copy_iter(&trans, iter); split_iter = bch2_trans_copy_iter(&trans, iter);
ret = PTR_ERR_OR_ZERO(split_iter);
if (ret)
goto err;
/* /*
* It's important that we don't go through the * It's important that we don't go through the
...@@ -502,8 +499,6 @@ static int __bch2_journal_replay_key(struct btree_trans *trans, ...@@ -502,8 +499,6 @@ static int __bch2_journal_replay_key(struct btree_trans *trans,
iter = bch2_trans_get_node_iter(trans, id, k->k.p, iter = bch2_trans_get_node_iter(trans, id, k->k.p,
BTREE_MAX_DEPTH, level, BTREE_MAX_DEPTH, level,
BTREE_ITER_INTENT); BTREE_ITER_INTENT);
if (IS_ERR(iter))
return PTR_ERR(iter);
/* /*
* iter->flags & BTREE_ITER_IS_EXTENTS triggers the update path to run * iter->flags & BTREE_ITER_IS_EXTENTS triggers the update path to run
...@@ -538,8 +533,7 @@ static int __bch2_alloc_replay_key(struct btree_trans *trans, struct bkey_i *k) ...@@ -538,8 +533,7 @@ static int __bch2_alloc_replay_key(struct btree_trans *trans, struct bkey_i *k)
BTREE_ITER_CACHED| BTREE_ITER_CACHED|
BTREE_ITER_CACHED_NOFILL| BTREE_ITER_CACHED_NOFILL|
BTREE_ITER_INTENT); BTREE_ITER_INTENT);
ret = PTR_ERR_OR_ZERO(iter) ?: ret = bch2_trans_update(trans, iter, k, BTREE_TRIGGER_NORUN);
bch2_trans_update(trans, iter, k, BTREE_TRIGGER_NORUN);
bch2_trans_iter_put(trans, iter); bch2_trans_iter_put(trans, iter);
return ret; return ret;
} }
......
...@@ -205,8 +205,6 @@ int bch2_hash_needs_whiteout(struct btree_trans *trans, ...@@ -205,8 +205,6 @@ int bch2_hash_needs_whiteout(struct btree_trans *trans,
int ret; int ret;
iter = bch2_trans_copy_iter(trans, start); iter = bch2_trans_copy_iter(trans, start);
if (IS_ERR(iter))
return PTR_ERR(iter);
bch2_btree_iter_next_slot(iter); bch2_btree_iter_next_slot(iter);
...@@ -253,11 +251,8 @@ int bch2_hash_set(struct btree_trans *trans, ...@@ -253,11 +251,8 @@ int bch2_hash_set(struct btree_trans *trans,
} }
if (!slot && if (!slot &&
!(flags & BCH_HASH_SET_MUST_REPLACE)) { !(flags & BCH_HASH_SET_MUST_REPLACE))
slot = bch2_trans_copy_iter(trans, iter); slot = bch2_trans_copy_iter(trans, iter);
if (IS_ERR(slot))
return PTR_ERR(slot);
}
if (k.k->type != KEY_TYPE_whiteout) if (k.k->type != KEY_TYPE_whiteout)
goto not_found; goto not_found;
......
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