mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 14:11:52 +00:00
bcachefs: bch2_bkey_make_mut() now calls bch2_trans_update()
It's safe to call bch2_trans_update with a k/v pair where the value hasn't been filled out, as long as the key part has been and the value is filled out by transaction commit time. This patch folds the bch2_trans_update() call into bch2_bkey_make_mut(), eliminating a bit of boilerplate. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
f12a798a89
commit
dbda63bbb0
@ -512,7 +512,7 @@ static inline struct bkey_i_alloc_v4 *bch2_alloc_to_v4_mut_inlined(struct btree_
|
||||
if (likely(k.k->type == KEY_TYPE_alloc_v4) &&
|
||||
((a = bkey_s_c_to_alloc_v4(k), true) &&
|
||||
BCH_ALLOC_V4_NR_BACKPOINTERS(a.v) == 0))
|
||||
return bch2_bkey_make_mut_typed(trans, k, alloc_v4);
|
||||
return bch2_bkey_make_mut_noupdate_typed(trans, k, alloc_v4);
|
||||
|
||||
return __bch2_alloc_to_v4_mut(trans, k);
|
||||
}
|
||||
|
@ -1591,7 +1591,7 @@ static int bch2_gc_write_reflink_key(struct btree_trans *trans,
|
||||
" should be %u",
|
||||
(bch2_bkey_val_to_text(&buf, c, k), buf.buf),
|
||||
r->refcount)) {
|
||||
struct bkey_i *new = bch2_bkey_make_mut(trans, k);
|
||||
struct bkey_i *new = bch2_bkey_make_mut(trans, iter, k, 0);
|
||||
|
||||
ret = PTR_ERR_OR_ZERO(new);
|
||||
if (ret)
|
||||
@ -1601,8 +1601,6 @@ static int bch2_gc_write_reflink_key(struct btree_trans *trans,
|
||||
new->k.type = KEY_TYPE_deleted;
|
||||
else
|
||||
*bkey_refcount(new) = cpu_to_le64(r->refcount);
|
||||
|
||||
ret = bch2_trans_update(trans, iter, new, 0);
|
||||
}
|
||||
fsck_err:
|
||||
printbuf_exit(&buf);
|
||||
@ -1918,13 +1916,13 @@ static int gc_btree_gens_key(struct btree_trans *trans,
|
||||
percpu_up_read(&c->mark_lock);
|
||||
return 0;
|
||||
update:
|
||||
u = bch2_bkey_make_mut(trans, k);
|
||||
u = bch2_bkey_make_mut(trans, iter, k, 0);
|
||||
ret = PTR_ERR_OR_ZERO(u);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
bch2_extent_normalize(c, bkey_i_to_s(u));
|
||||
return bch2_trans_update(trans, iter, u, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bch2_alloc_write_oldest_gen(struct btree_trans *trans, struct btree_iter *iter,
|
||||
|
@ -183,7 +183,7 @@ static inline void bch2_trans_reset_updates(struct btree_trans *trans)
|
||||
}
|
||||
}
|
||||
|
||||
static inline struct bkey_i *__bch2_bkey_make_mut(struct btree_trans *trans, struct bkey_s_c k,
|
||||
static inline struct bkey_i *__bch2_bkey_make_mut_noupdate(struct btree_trans *trans, struct bkey_s_c k,
|
||||
unsigned type, unsigned min_bytes)
|
||||
{
|
||||
unsigned bytes = max_t(unsigned, min_bytes, bkey_bytes(k.k));
|
||||
@ -205,13 +205,39 @@ static inline struct bkey_i *__bch2_bkey_make_mut(struct btree_trans *trans, str
|
||||
return mut;
|
||||
}
|
||||
|
||||
static inline struct bkey_i *bch2_bkey_make_mut(struct btree_trans *trans, struct bkey_s_c k)
|
||||
static inline struct bkey_i *bch2_bkey_make_mut_noupdate(struct btree_trans *trans, struct bkey_s_c k)
|
||||
{
|
||||
return __bch2_bkey_make_mut(trans, k, 0, 0);
|
||||
return __bch2_bkey_make_mut_noupdate(trans, k, 0, 0);
|
||||
}
|
||||
|
||||
#define bch2_bkey_make_mut_typed(_trans, _k, _type) \
|
||||
bkey_i_to_##_type(__bch2_bkey_make_mut(_trans, _k, \
|
||||
#define bch2_bkey_make_mut_noupdate_typed(_trans, _k, _type) \
|
||||
bkey_i_to_##_type(__bch2_bkey_make_mut_noupdate(_trans, _k, \
|
||||
KEY_TYPE_##_type, sizeof(struct bkey_i_##_type)))
|
||||
|
||||
static inline struct bkey_i *__bch2_bkey_make_mut(struct btree_trans *trans, struct btree_iter *iter,
|
||||
struct bkey_s_c k, unsigned flags,
|
||||
unsigned type, unsigned min_bytes)
|
||||
{
|
||||
struct bkey_i *mut = __bch2_bkey_make_mut_noupdate(trans, k, type, min_bytes);
|
||||
int ret;
|
||||
|
||||
if (IS_ERR(mut))
|
||||
return mut;
|
||||
|
||||
ret = bch2_trans_update(trans, iter, mut, flags);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
return mut;
|
||||
}
|
||||
|
||||
static inline struct bkey_i *bch2_bkey_make_mut(struct btree_trans *trans, struct btree_iter *iter,
|
||||
struct bkey_s_c k, unsigned flags)
|
||||
{
|
||||
return __bch2_bkey_make_mut(trans, iter, k, flags, 0, 0);
|
||||
}
|
||||
|
||||
#define bch2_bkey_make_mut_typed(_trans, _iter, _k, _flags, _type) \
|
||||
bkey_i_to_##_type(__bch2_bkey_make_mut(_trans, _iter, _k, _flags,\
|
||||
KEY_TYPE_##_type, sizeof(struct bkey_i_##_type)))
|
||||
|
||||
static inline struct bkey_i *__bch2_bkey_get_mut_noupdate(struct btree_trans *trans,
|
||||
@ -223,7 +249,7 @@ static inline struct bkey_i *__bch2_bkey_get_mut_noupdate(struct btree_trans *tr
|
||||
btree_id, pos, flags|BTREE_ITER_INTENT, type);
|
||||
struct bkey_i *ret = unlikely(IS_ERR(k.k))
|
||||
? ERR_CAST(k.k)
|
||||
: __bch2_bkey_make_mut(trans, k, 0, min_bytes);
|
||||
: __bch2_bkey_make_mut_noupdate(trans, k, 0, min_bytes);
|
||||
if (unlikely(IS_ERR(ret)))
|
||||
bch2_trans_iter_exit(trans, iter);
|
||||
return ret;
|
||||
|
@ -1268,7 +1268,7 @@ static noinline int extent_front_merge(struct btree_trans *trans,
|
||||
struct bkey_i *update;
|
||||
int ret;
|
||||
|
||||
update = bch2_bkey_make_mut(trans, k);
|
||||
update = bch2_bkey_make_mut_noupdate(trans, k);
|
||||
ret = PTR_ERR_OR_ZERO(update);
|
||||
if (ret)
|
||||
return ret;
|
||||
@ -1390,7 +1390,7 @@ int bch2_trans_update_extent(struct btree_trans *trans,
|
||||
trans->extra_journal_res += compressed_sectors;
|
||||
|
||||
if (front_split) {
|
||||
update = bch2_bkey_make_mut(trans, k);
|
||||
update = bch2_bkey_make_mut_noupdate(trans, k);
|
||||
if ((ret = PTR_ERR_OR_ZERO(update)))
|
||||
goto err;
|
||||
|
||||
@ -1404,7 +1404,7 @@ int bch2_trans_update_extent(struct btree_trans *trans,
|
||||
|
||||
if (k.k->p.snapshot != insert->k.p.snapshot &&
|
||||
(front_split || back_split)) {
|
||||
update = bch2_bkey_make_mut(trans, k);
|
||||
update = bch2_bkey_make_mut_noupdate(trans, k);
|
||||
if ((ret = PTR_ERR_OR_ZERO(update)))
|
||||
goto err;
|
||||
|
||||
@ -1443,7 +1443,7 @@ int bch2_trans_update_extent(struct btree_trans *trans,
|
||||
}
|
||||
|
||||
if (back_split) {
|
||||
update = bch2_bkey_make_mut(trans, k);
|
||||
update = bch2_bkey_make_mut_noupdate(trans, k);
|
||||
if ((ret = PTR_ERR_OR_ZERO(update)))
|
||||
goto err;
|
||||
|
||||
|
@ -765,7 +765,7 @@ static int hash_redo_key(struct btree_trans *trans,
|
||||
if (IS_ERR(delete))
|
||||
return PTR_ERR(delete);
|
||||
|
||||
tmp = bch2_bkey_make_mut(trans, k);
|
||||
tmp = bch2_bkey_make_mut_noupdate(trans, k);
|
||||
if (IS_ERR(tmp))
|
||||
return PTR_ERR(tmp);
|
||||
|
||||
|
@ -1393,7 +1393,7 @@ static int bch2_nocow_write_convert_one_unwritten(struct btree_trans *trans,
|
||||
return 0;
|
||||
}
|
||||
|
||||
new = bch2_bkey_make_mut(trans, k);
|
||||
new = bch2_bkey_make_mut_noupdate(trans, k);
|
||||
ret = PTR_ERR_OR_ZERO(new);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
@ -49,7 +49,7 @@ static int bch2_dev_usrdata_drop_key(struct btree_trans *trans,
|
||||
if (!bch2_bkey_has_device_c(k, dev_idx))
|
||||
return 0;
|
||||
|
||||
n = bch2_bkey_make_mut(trans, k);
|
||||
n = bch2_bkey_make_mut(trans, iter, k, BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE);
|
||||
ret = PTR_ERR_OR_ZERO(n);
|
||||
if (ret)
|
||||
return ret;
|
||||
@ -73,8 +73,7 @@ static int bch2_dev_usrdata_drop_key(struct btree_trans *trans,
|
||||
*/
|
||||
if (bkey_deleted(&n->k))
|
||||
n->k.size = 0;
|
||||
|
||||
return bch2_trans_update(trans, iter, n, BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bch2_dev_usrdata_drop(struct bch_fs *c, unsigned dev_idx, int flags)
|
||||
|
@ -251,7 +251,7 @@ static int bch2_extent_drop_ptrs(struct btree_trans *trans,
|
||||
struct bkey_i *n;
|
||||
int ret;
|
||||
|
||||
n = bch2_bkey_make_mut(trans, k);
|
||||
n = bch2_bkey_make_mut_noupdate(trans, k);
|
||||
ret = PTR_ERR_OR_ZERO(n);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
Loading…
Reference in New Issue
Block a user