bcachefs: Check for errors from bch2_trans_update()

Upcoming refactoring is going to change bch2_trans_update() to start
returning transaction restarts.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2021-06-02 00:15:07 -04:00 committed by Kent Overstreet
parent 01254036a3
commit bc3f8b25f3
13 changed files with 54 additions and 54 deletions

View File

@ -386,7 +386,7 @@ int bch2_acl_chmod(struct btree_trans *trans,
}
new->k.p = iter->pos;
bch2_trans_update(trans, iter, &new->k_i, 0);
ret = bch2_trans_update(trans, iter, &new->k_i, 0);
*new_acl = acl;
acl = NULL;
err:

View File

@ -340,9 +340,9 @@ static int bch2_alloc_write_key(struct btree_trans *trans,
return 0;
bch2_alloc_pack(c, &a, new_u);
bch2_trans_update(trans, iter, &a.k,
BTREE_TRIGGER_NORUN);
ret = bch2_trans_commit(trans, NULL, NULL,
ret = bch2_trans_update(trans, iter, &a.k,
BTREE_TRIGGER_NORUN) ?:
bch2_trans_commit(trans, NULL, NULL,
BTREE_INSERT_NOFAIL|flags);
err:
if (ret == -EINTR)
@ -726,7 +726,8 @@ static int bucket_invalidate_btree(struct btree_trans *trans,
u.write_time = atomic64_read(&c->io_clock[WRITE].now);
bch2_alloc_pack(c, a, u);
bch2_trans_update(trans, iter, &a->k, BTREE_TRIGGER_BUCKET_INVALIDATE);
ret = bch2_trans_update(trans, iter, &a->k,
BTREE_TRIGGER_BUCKET_INVALIDATE);
err:
bch2_trans_iter_put(trans, iter);
return ret;

View File

@ -1668,9 +1668,10 @@ static int bch2_gc_btree_gens(struct bch_fs *c, enum btree_id btree_id)
bch2_bkey_buf_reassemble(&sk, c, k);
bch2_extent_normalize(c, bkey_i_to_s(sk.k));
bch2_trans_update(&trans, iter, sk.k, 0);
commit_err = bch2_trans_commit(&trans, NULL, NULL,
commit_err =
bch2_trans_update(&trans, iter, sk.k, 0) ?:
bch2_trans_commit(&trans, NULL, NULL,
BTREE_INSERT_NOWAIT|
BTREE_INSERT_NOFAIL);
if (commit_err == -EINTR) {

View File

@ -1198,9 +1198,9 @@ int bch2_btree_delete_at(struct btree_trans *trans,
bkey_init(&k.k);
k.k.p = iter->pos;
bch2_trans_update(trans, iter, &k, 0);
return bch2_trans_commit(trans, NULL, NULL,
BTREE_INSERT_NOFAIL|flags);
return bch2_trans_update(trans, iter, &k, 0) ?:
bch2_trans_commit(trans, NULL, NULL,
BTREE_INSERT_NOFAIL|flags);
}
int bch2_btree_delete_range_trans(struct btree_trans *trans, enum btree_id id,
@ -1251,8 +1251,8 @@ int bch2_btree_delete_range_trans(struct btree_trans *trans, enum btree_id id,
break;
}
bch2_trans_update(trans, iter, &delete, 0);
ret = bch2_trans_commit(trans, NULL, journal_seq,
ret = bch2_trans_update(trans, iter, &delete, 0) ?:
bch2_trans_commit(trans, NULL, journal_seq,
BTREE_INSERT_NOFAIL);
if (ret)
break;

View File

@ -1877,7 +1877,9 @@ static int __bch2_trans_mark_reflink_p(struct btree_trans *trans,
}
bch2_btree_iter_set_pos(iter, bkey_start_pos(k.k));
bch2_trans_update(trans, iter, n, 0);
ret = bch2_trans_update(trans, iter, n, 0);
if (ret)
goto err;
out:
ret = sectors;
err:

View File

@ -741,9 +741,8 @@ static int ec_stripe_bkey_insert(struct bch_fs *c,
stripe->k.p = iter->pos;
bch2_trans_update(&trans, iter, &stripe->k_i, 0);
ret = bch2_trans_commit(&trans, res, NULL,
ret = bch2_trans_update(&trans, iter, &stripe->k_i, 0) ?:
bch2_trans_commit(&trans, res, NULL,
BTREE_INSERT_NOFAIL);
err:
bch2_trans_iter_put(&trans, iter);
@ -791,7 +790,7 @@ static int ec_stripe_bkey_update(struct btree_trans *trans,
stripe_blockcount_set(&new->v, i,
stripe_blockcount_get(existing, i));
bch2_trans_update(trans, iter, &new->k_i, 0);
ret = bch2_trans_update(trans, iter, &new->k_i, 0);
err:
bch2_trans_iter_put(trans, iter);
return ret;
@ -864,9 +863,8 @@ static int ec_stripe_update_ptrs(struct bch_fs *c,
extent_stripe_ptr_add(e, s, ec_ptr, block);
bch2_btree_iter_set_pos(iter, bkey_start_pos(&sk.k->k));
bch2_trans_update(&trans, iter, sk.k, 0);
ret = bch2_trans_commit(&trans, NULL, NULL,
ret = bch2_trans_update(&trans, iter, sk.k, 0) ?:
bch2_trans_commit(&trans, NULL, NULL,
BTREE_INSERT_NOFAIL);
if (ret == -EINTR)
ret = 0;
@ -1588,8 +1586,7 @@ static int __bch2_stripe_write_key(struct btree_trans *trans,
stripe_blockcount_set(&new_key->v, i,
m->block_sectors[i]);
bch2_trans_update(trans, iter, &new_key->k_i, 0);
return 0;
return bch2_trans_update(trans, iter, &new_key->k_i, 0);
}
int bch2_stripes_write(struct bch_fs *c, unsigned flags)

View File

@ -305,9 +305,8 @@ static int hash_redo_key(struct btree_trans *trans,
bkey_init(&delete->k);
delete->k.p = k_iter->pos;
bch2_trans_update(trans, k_iter, delete, 0);
return bch2_hash_set(trans, desc, hash_info, k_iter->pos.inode, tmp, 0);
return bch2_trans_update(trans, k_iter, delete, 0) ?:
bch2_hash_set(trans, desc, hash_info, k_iter->pos.inode, tmp, 0);
}
static int fsck_hash_delete_at(struct btree_trans *trans,
@ -563,12 +562,12 @@ static int fix_overlapping_extent(struct btree_trans *trans,
BTREE_ITER_INTENT|BTREE_ITER_NOT_EXTENTS);
BUG_ON(iter->flags & BTREE_ITER_IS_EXTENTS);
bch2_trans_update(trans, iter, u, BTREE_TRIGGER_NORUN);
ret = bch2_trans_update(trans, iter, u, BTREE_TRIGGER_NORUN) ?:
bch2_trans_commit(trans, NULL, NULL,
BTREE_INSERT_NOFAIL|
BTREE_INSERT_LAZY_RW);
bch2_trans_iter_put(trans, iter);
return bch2_trans_commit(trans, NULL, NULL,
BTREE_INSERT_NOFAIL|
BTREE_INSERT_LAZY_RW);
return ret;
}
static int inode_backpointer_exists(struct btree_trans *trans,
@ -887,7 +886,7 @@ static int check_dirents(struct bch_fs *c)
ret = __bch2_trans_do(&trans, NULL, NULL,
BTREE_INSERT_NOFAIL|
BTREE_INSERT_LAZY_RW,
(bch2_trans_update(&trans, iter, &n->k_i, 0), 0));
bch2_trans_update(&trans, iter, &n->k_i, 0));
kfree(n);
if (ret)
goto err;

View File

@ -333,8 +333,7 @@ int bch2_inode_write(struct btree_trans *trans,
bch2_inode_pack(trans->c, inode_p, inode);
inode_p->inode.k.p.snapshot = iter->snapshot;
bch2_trans_update(trans, iter, &inode_p->inode.k_i, 0);
return 0;
return bch2_trans_update(trans, iter, &inode_p->inode.k_i, 0);
}
const char *bch2_inode_invalid(const struct bch_fs *c, struct bkey_s_c k)
@ -629,9 +628,8 @@ int bch2_inode_rm(struct bch_fs *c, u64 inode_nr, bool cached)
delete.k.p = iter->pos;
delete.v.bi_generation = cpu_to_le32(inode_u.bi_generation + 1);
bch2_trans_update(&trans, iter, &delete.k_i, 0);
ret = bch2_trans_commit(&trans, NULL, NULL,
ret = bch2_trans_update(&trans, iter, &delete.k_i, 0) ?:
bch2_trans_commit(&trans, NULL, NULL,
BTREE_INSERT_NOFAIL);
err:
bch2_trans_iter_put(&trans, iter);

View File

@ -311,8 +311,9 @@ int bch2_extent_update(struct btree_trans *trans,
inode_iter = bch2_inode_peek(trans, &inode_u,
k->k.p.inode, BTREE_ITER_INTENT);
if (IS_ERR(inode_iter))
return PTR_ERR(inode_iter);
ret = PTR_ERR_OR_ZERO(inode_iter);
if (ret)
return ret;
/*
* XXX:
@ -339,11 +340,14 @@ int bch2_extent_update(struct btree_trans *trans,
inode_p.inode.k.p.snapshot = iter->snapshot;
bch2_trans_update(trans, inode_iter,
ret = bch2_trans_update(trans, inode_iter,
&inode_p.inode.k_i, 0);
}
bch2_trans_iter_put(trans, inode_iter);
if (ret)
return ret;
}
ret = bch2_trans_update(trans, iter, k, 0) ?:
@ -1780,7 +1784,7 @@ static int __bch2_rbio_narrow_crcs(struct btree_trans *trans,
if (!bch2_bkey_narrow_crcs(new, new_crc))
goto out;
bch2_trans_update(trans, iter, new, 0);
ret = bch2_trans_update(trans, iter, new, 0);
out:
bch2_trans_iter_put(trans, iter);
return ret;

View File

@ -73,9 +73,8 @@ static int __bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags
bch2_btree_iter_set_pos(iter, bkey_start_pos(&sk.k->k));
bch2_trans_update(&trans, iter, sk.k, 0);
ret = bch2_trans_commit(&trans, NULL, NULL,
ret = bch2_trans_update(&trans, iter, sk.k, 0) ?:
bch2_trans_commit(&trans, NULL, NULL,
BTREE_INSERT_NOFAIL);
/*

View File

@ -162,9 +162,8 @@ int bch2_migrate_index_update(struct bch_write_op *op)
goto out;
}
bch2_trans_update(&trans, iter, insert, 0);
ret = bch2_trans_commit(&trans, &op->res,
ret = bch2_trans_update(&trans, iter, insert, 0) ?:
bch2_trans_commit(&trans, &op->res,
op_journal_seq(op),
BTREE_INSERT_NOFAIL|
m->data_opts.btree_insert_flags);

View File

@ -281,7 +281,7 @@ int bch2_hash_set(struct btree_trans *trans,
swap(iter, slot);
insert->k.p = iter->pos;
bch2_trans_update(trans, iter, insert, 0);
ret = bch2_trans_update(trans, iter, insert, 0);
}
goto out;
@ -296,20 +296,20 @@ int bch2_hash_delete_at(struct btree_trans *trans,
struct bkey_i *delete;
int ret;
delete = bch2_trans_kmalloc(trans, sizeof(*delete));
ret = PTR_ERR_OR_ZERO(delete);
if (ret)
return ret;
ret = bch2_hash_needs_whiteout(trans, desc, info, iter);
if (ret < 0)
return ret;
delete = bch2_trans_kmalloc(trans, sizeof(*delete));
if (IS_ERR(delete))
return PTR_ERR(delete);
bkey_init(&delete->k);
delete->k.p = iter->pos;
delete->k.type = ret ? KEY_TYPE_hash_whiteout : KEY_TYPE_deleted;
bch2_trans_update(trans, iter, delete, 0);
return 0;
return bch2_trans_update(trans, iter, delete, 0);
}
static __always_inline

View File

@ -621,7 +621,7 @@ static int __do_delete(struct btree_trans *trans, struct bpos pos)
bkey_init(&delete.k);
delete.k.p = k.k->p;
bch2_trans_update(trans, iter, &delete, 0);
ret = bch2_trans_update(trans, iter, &delete, 0);
err:
bch2_trans_iter_put(trans, iter);
return ret;