2017-03-17 14:18:50 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef _BCACHEFS_BTREE_UPDATE_H
|
|
|
|
#define _BCACHEFS_BTREE_UPDATE_H
|
|
|
|
|
|
|
|
#include "btree_iter.h"
|
|
|
|
#include "journal.h"
|
|
|
|
|
|
|
|
struct bch_fs;
|
|
|
|
struct btree;
|
|
|
|
|
2022-10-09 17:04:38 +08:00
|
|
|
void bch2_btree_node_prep_for_write(struct btree_trans *,
|
|
|
|
struct btree_path *, struct btree *);
|
2021-08-31 03:18:31 +08:00
|
|
|
bool bch2_btree_bset_insert_key(struct btree_trans *, struct btree_path *,
|
2021-08-25 09:30:06 +08:00
|
|
|
struct btree *, struct btree_node_iter *,
|
|
|
|
struct bkey_i *);
|
2023-03-07 20:28:20 +08:00
|
|
|
|
|
|
|
int bch2_btree_node_flush0(struct journal *, struct journal_entry_pin *, u64);
|
|
|
|
int bch2_btree_node_flush1(struct journal *, struct journal_entry_pin *, u64);
|
2020-02-09 08:06:31 +08:00
|
|
|
void bch2_btree_add_journal_pin(struct bch_fs *, struct btree *, u64);
|
2017-03-17 14:18:50 +08:00
|
|
|
|
bcachefs: Btree write buffer
This adds a new method of doing btree updates - a straight write buffer,
implemented as a flat fixed size array.
This is only useful when we don't need to read from the btree in order
to do the update, and when reading is infrequent - perfect for the LRU
btree.
This will make LRU btree updates fast enough that we'll be able to use
it for persistently indexing buckets by fragmentation, which will be a
massive boost to copygc performance.
Changes:
- A new btree_insert_type enum, for btree_insert_entries. Specifies
btree, btree key cache, or btree write buffer.
- bch2_trans_update_buffered(): updates via the btree write buffer
don't need a btree path, so we need a new update path.
- Transaction commit path changes:
The update to the btree write buffer both mutates global, and can
fail if there isn't currently room. Therefore we do all write buffer
updates in the transaction all at once, and also if it fails we have
to revert filesystem usage counter changes.
If there isn't room we flush the write buffer in the transaction
commit error path and retry.
- A new persistent option, for specifying the number of entries in the
write buffer.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-01-04 13:00:50 +08:00
|
|
|
void bch2_btree_insert_key_leaf(struct btree_trans *, struct btree_path *,
|
|
|
|
struct bkey_i *, u64);
|
|
|
|
|
2023-11-12 05:31:50 +08:00
|
|
|
#define BCH_TRANS_COMMIT_FLAGS() \
|
|
|
|
x(no_enospc, "don't check for enospc") \
|
|
|
|
x(no_check_rw, "don't attempt to take a ref on c->writes") \
|
|
|
|
x(lazy_rw, "go read-write if we haven't yet - only for use in recovery") \
|
|
|
|
x(no_journal_res, "don't take a journal reservation, instead " \
|
|
|
|
"pin journal entry referred to by trans->journal_res.seq") \
|
|
|
|
x(journal_reclaim, "operation required for journal reclaim; may return error" \
|
|
|
|
"instead of deadlocking if BCH_WATERMARK_reclaim not specified")\
|
|
|
|
|
|
|
|
enum __bch_trans_commit_flags {
|
2023-06-28 05:32:38 +08:00
|
|
|
/* First bits for bch_watermark: */
|
2023-11-12 05:31:50 +08:00
|
|
|
__BCH_TRANS_COMMIT_FLAGS_START = BCH_WATERMARK_BITS,
|
|
|
|
#define x(n, ...) __BCH_TRANS_COMMIT_##n,
|
|
|
|
BCH_TRANS_COMMIT_FLAGS()
|
|
|
|
#undef x
|
2017-03-17 14:18:50 +08:00
|
|
|
};
|
|
|
|
|
2023-11-12 05:31:50 +08:00
|
|
|
enum bch_trans_commit_flags {
|
|
|
|
#define x(n, ...) BCH_TRANS_COMMIT_##n = BIT(__BCH_TRANS_COMMIT_##n),
|
|
|
|
BCH_TRANS_COMMIT_FLAGS()
|
|
|
|
#undef x
|
|
|
|
};
|
2019-03-08 08:46:10 +08:00
|
|
|
|
2024-04-14 05:49:23 +08:00
|
|
|
void bch2_trans_commit_flags_to_text(struct printbuf *, enum bch_trans_commit_flags);
|
|
|
|
|
2022-04-10 03:07:11 +08:00
|
|
|
int bch2_btree_delete_extent_at(struct btree_trans *, struct btree_iter *,
|
|
|
|
unsigned, unsigned);
|
2019-03-14 08:49:16 +08:00
|
|
|
int bch2_btree_delete_at(struct btree_trans *, struct btree_iter *, unsigned);
|
2023-08-28 06:27:41 +08:00
|
|
|
int bch2_btree_delete(struct btree_trans *, enum btree_id, struct bpos, unsigned);
|
2017-03-17 14:18:50 +08:00
|
|
|
|
2023-02-17 12:09:27 +08:00
|
|
|
int bch2_btree_insert_nonextent(struct btree_trans *, enum btree_id,
|
2024-04-08 06:05:34 +08:00
|
|
|
struct bkey_i *, enum btree_iter_update_trigger_flags);
|
2023-02-17 12:09:27 +08:00
|
|
|
|
2023-09-12 07:48:07 +08:00
|
|
|
int bch2_btree_insert_trans(struct btree_trans *, enum btree_id, struct bkey_i *,
|
2024-04-08 06:05:34 +08:00
|
|
|
enum btree_iter_update_trigger_flags);
|
2017-03-17 14:18:50 +08:00
|
|
|
int bch2_btree_insert(struct bch_fs *, enum btree_id, struct bkey_i *,
|
2023-09-13 06:41:22 +08:00
|
|
|
struct disk_reservation *, int flags);
|
2017-03-17 14:18:50 +08:00
|
|
|
|
2020-11-21 10:28:55 +08:00
|
|
|
int bch2_btree_delete_range_trans(struct btree_trans *, enum btree_id,
|
2021-04-20 12:15:44 +08:00
|
|
|
struct bpos, struct bpos, unsigned, u64 *);
|
2017-03-17 14:18:50 +08:00
|
|
|
int bch2_btree_delete_range(struct bch_fs *, enum btree_id,
|
2021-12-30 02:49:34 +08:00
|
|
|
struct bpos, struct bpos, unsigned, u64 *);
|
2017-03-17 14:18:50 +08:00
|
|
|
|
2024-02-09 08:23:56 +08:00
|
|
|
int bch2_btree_bit_mod(struct btree_trans *, enum btree_id, struct bpos, bool);
|
2024-02-09 08:10:19 +08:00
|
|
|
int bch2_btree_bit_mod_buffered(struct btree_trans *, enum btree_id, struct bpos, bool);
|
2023-07-17 12:56:07 +08:00
|
|
|
|
2023-11-27 09:18:16 +08:00
|
|
|
static inline int bch2_btree_delete_at_buffered(struct btree_trans *trans,
|
|
|
|
enum btree_id btree, struct bpos pos)
|
|
|
|
{
|
2024-02-09 08:10:19 +08:00
|
|
|
return bch2_btree_bit_mod_buffered(trans, btree, pos, false);
|
2023-11-27 09:18:16 +08:00
|
|
|
}
|
|
|
|
|
2023-05-28 11:19:13 +08:00
|
|
|
int __bch2_insert_snapshot_whiteouts(struct btree_trans *, enum btree_id,
|
|
|
|
struct bpos, struct bpos);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For use when splitting extents in existing snapshots:
|
|
|
|
*
|
|
|
|
* If @old_pos is an interior snapshot node, iterate over descendent snapshot
|
|
|
|
* nodes: for every descendent snapshot in whiche @old_pos is overwritten and
|
|
|
|
* not visible, emit a whiteout at @new_pos.
|
|
|
|
*/
|
|
|
|
static inline int bch2_insert_snapshot_whiteouts(struct btree_trans *trans,
|
|
|
|
enum btree_id btree,
|
|
|
|
struct bpos old_pos,
|
|
|
|
struct bpos new_pos)
|
|
|
|
{
|
|
|
|
if (!btree_type_has_snapshots(btree) ||
|
|
|
|
bkey_eq(old_pos, new_pos))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return __bch2_insert_snapshot_whiteouts(trans, btree, old_pos, new_pos);
|
|
|
|
}
|
|
|
|
|
2023-07-21 12:27:19 +08:00
|
|
|
int bch2_trans_update_extent_overwrite(struct btree_trans *, struct btree_iter *,
|
2024-04-08 06:05:34 +08:00
|
|
|
enum btree_iter_update_trigger_flags,
|
2023-07-21 12:27:19 +08:00
|
|
|
struct bkey_s_c, struct bkey_s_c);
|
2022-01-09 10:22:31 +08:00
|
|
|
|
2023-04-28 11:20:18 +08:00
|
|
|
int bch2_bkey_get_empty_slot(struct btree_trans *, struct btree_iter *,
|
|
|
|
enum btree_id, struct bpos);
|
|
|
|
|
2021-12-05 13:30:49 +08:00
|
|
|
int __must_check bch2_trans_update(struct btree_trans *, struct btree_iter *,
|
2024-04-08 06:05:34 +08:00
|
|
|
struct bkey_i *, enum btree_iter_update_trigger_flags);
|
2022-01-09 10:22:31 +08:00
|
|
|
|
2023-12-11 05:48:22 +08:00
|
|
|
struct jset_entry *__bch2_trans_jset_entry_alloc(struct btree_trans *, unsigned);
|
|
|
|
|
|
|
|
static inline struct jset_entry *btree_trans_journal_entries_top(struct btree_trans *trans)
|
|
|
|
{
|
|
|
|
return (void *) ((u64 *) trans->journal_entries + trans->journal_entries_u64s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct jset_entry *
|
|
|
|
bch2_trans_jset_entry_alloc(struct btree_trans *trans, unsigned u64s)
|
|
|
|
{
|
|
|
|
if (!trans->journal_entries ||
|
|
|
|
trans->journal_entries_u64s + u64s > trans->journal_entries_size)
|
|
|
|
return __bch2_trans_jset_entry_alloc(trans, u64s);
|
|
|
|
|
|
|
|
struct jset_entry *e = btree_trans_journal_entries_top(trans);
|
|
|
|
trans->journal_entries_u64s += u64s;
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2023-11-12 10:43:47 +08:00
|
|
|
int bch2_btree_insert_clone_trans(struct btree_trans *, enum btree_id, struct bkey_i *);
|
|
|
|
|
|
|
|
static inline int __must_check bch2_trans_update_buffered(struct btree_trans *trans,
|
|
|
|
enum btree_id btree,
|
|
|
|
struct bkey_i *k)
|
|
|
|
{
|
|
|
|
if (unlikely(trans->journal_replay_not_finished))
|
|
|
|
return bch2_btree_insert_clone_trans(trans, btree, k);
|
|
|
|
|
|
|
|
struct jset_entry *e = bch2_trans_jset_entry_alloc(trans, jset_u64s(k->k.u64s));
|
|
|
|
int ret = PTR_ERR_OR_ZERO(e);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
journal_entry_init(e, BCH_JSET_ENTRY_write_buffer_keys, btree, 0, k->k.u64s);
|
|
|
|
bkey_copy(e->start, k);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-02-04 10:51:56 +08:00
|
|
|
void bch2_trans_commit_hook(struct btree_trans *,
|
|
|
|
struct btree_trans_commit_hook *);
|
2023-02-10 02:22:12 +08:00
|
|
|
int __bch2_trans_commit(struct btree_trans *, unsigned);
|
2019-10-20 07:03:23 +08:00
|
|
|
|
2023-09-13 06:41:22 +08:00
|
|
|
__printf(2, 3) int bch2_fs_log_msg(struct bch_fs *, const char *, ...);
|
|
|
|
__printf(2, 3) int bch2_journal_log_msg(struct bch_fs *, const char *, ...);
|
2022-03-31 03:44:12 +08:00
|
|
|
|
2019-10-20 07:03:23 +08:00
|
|
|
/**
|
|
|
|
* bch2_trans_commit - insert keys at given iterator positions
|
|
|
|
*
|
|
|
|
* This is main entry point for btree updates.
|
|
|
|
*
|
|
|
|
* Return values:
|
|
|
|
* -EROFS: filesystem read only
|
|
|
|
* -EIO: journal or btree node IO error
|
|
|
|
*/
|
|
|
|
static inline int bch2_trans_commit(struct btree_trans *trans,
|
|
|
|
struct disk_reservation *disk_res,
|
|
|
|
u64 *journal_seq,
|
|
|
|
unsigned flags)
|
|
|
|
{
|
|
|
|
trans->disk_res = disk_res;
|
|
|
|
trans->journal_seq = journal_seq;
|
|
|
|
|
2023-02-10 02:22:12 +08:00
|
|
|
return __bch2_trans_commit(trans, flags);
|
2019-10-20 07:03:23 +08:00
|
|
|
}
|
2017-03-17 14:18:50 +08:00
|
|
|
|
2022-07-13 17:25:29 +08:00
|
|
|
#define commit_do(_trans, _disk_res, _journal_seq, _flags, _do) \
|
2021-04-07 15:11:07 +08:00
|
|
|
lockrestart_do(_trans, _do ?: bch2_trans_commit(_trans, (_disk_res),\
|
|
|
|
(_journal_seq), (_flags)))
|
|
|
|
|
2022-07-18 07:35:38 +08:00
|
|
|
#define nested_commit_do(_trans, _disk_res, _journal_seq, _flags, _do) \
|
|
|
|
nested_lockrestart_do(_trans, _do ?: bch2_trans_commit(_trans, (_disk_res),\
|
|
|
|
(_journal_seq), (_flags)))
|
|
|
|
|
2022-07-14 14:08:58 +08:00
|
|
|
#define bch2_trans_run(_c, _do) \
|
|
|
|
({ \
|
2023-09-13 05:16:02 +08:00
|
|
|
struct btree_trans *trans = bch2_trans_get(_c); \
|
|
|
|
int _ret = (_do); \
|
|
|
|
bch2_trans_put(trans); \
|
2022-07-14 14:08:58 +08:00
|
|
|
_ret; \
|
|
|
|
})
|
|
|
|
|
2023-09-13 05:16:02 +08:00
|
|
|
#define bch2_trans_do(_c, _disk_res, _journal_seq, _flags, _do) \
|
|
|
|
bch2_trans_run(_c, commit_do(trans, _disk_res, _journal_seq, _flags, _do))
|
|
|
|
|
2019-09-23 06:49:16 +08:00
|
|
|
#define trans_for_each_update(_trans, _i) \
|
2023-12-17 10:31:26 +08:00
|
|
|
for (struct btree_insert_entry *_i = (_trans)->updates; \
|
2019-09-23 06:49:16 +08:00
|
|
|
(_i) < (_trans)->updates + (_trans)->nr_updates; \
|
2019-03-16 05:11:58 +08:00
|
|
|
(_i)++)
|
|
|
|
|
2022-05-29 23:38:48 +08:00
|
|
|
static inline void bch2_trans_reset_updates(struct btree_trans *trans)
|
|
|
|
{
|
|
|
|
trans_for_each_update(trans, i)
|
2023-12-11 05:10:24 +08:00
|
|
|
bch2_path_put(trans, i->path, true);
|
2022-05-29 23:38:48 +08:00
|
|
|
|
|
|
|
trans->nr_updates = 0;
|
2023-12-11 05:48:22 +08:00
|
|
|
trans->journal_entries_u64s = 0;
|
2022-05-29 23:38:48 +08:00
|
|
|
trans->hooks = NULL;
|
2023-12-11 15:31:12 +08:00
|
|
|
trans->extra_disk_res = 0;
|
2023-02-06 03:07:34 +08:00
|
|
|
|
|
|
|
if (trans->fs_usage_deltas) {
|
|
|
|
trans->fs_usage_deltas->used = 0;
|
|
|
|
memset((void *) trans->fs_usage_deltas +
|
|
|
|
offsetof(struct replicas_delta_list, memset_start), 0,
|
|
|
|
(void *) &trans->fs_usage_deltas->memset_end -
|
|
|
|
(void *) &trans->fs_usage_deltas->memset_start);
|
|
|
|
}
|
2022-05-29 23:38:48 +08:00
|
|
|
}
|
|
|
|
|
2023-05-01 07:21:06 +08:00
|
|
|
static inline struct bkey_i *__bch2_bkey_make_mut_noupdate(struct btree_trans *trans, struct bkey_s_c k,
|
2023-04-28 11:48:33 +08:00
|
|
|
unsigned type, unsigned min_bytes)
|
2023-05-01 08:58:59 +08:00
|
|
|
{
|
2023-04-28 11:48:33 +08:00
|
|
|
unsigned bytes = max_t(unsigned, min_bytes, bkey_bytes(k.k));
|
|
|
|
struct bkey_i *mut;
|
|
|
|
|
|
|
|
if (type && k.k->type != type)
|
|
|
|
return ERR_PTR(-ENOENT);
|
2023-05-01 08:58:59 +08:00
|
|
|
|
2023-04-28 11:48:33 +08:00
|
|
|
mut = bch2_trans_kmalloc_nomemzero(trans, bytes);
|
|
|
|
if (!IS_ERR(mut)) {
|
2023-05-01 08:58:59 +08:00
|
|
|
bkey_reassemble(mut, k);
|
2023-04-28 11:48:33 +08:00
|
|
|
|
|
|
|
if (unlikely(bytes > bkey_bytes(k.k))) {
|
|
|
|
memset((void *) mut + bkey_bytes(k.k), 0,
|
|
|
|
bytes - bkey_bytes(k.k));
|
|
|
|
mut->k.u64s = DIV_ROUND_UP(bytes, sizeof(u64));
|
|
|
|
}
|
|
|
|
}
|
2023-05-01 08:58:59 +08:00
|
|
|
return mut;
|
|
|
|
}
|
|
|
|
|
2023-05-01 07:21:06 +08:00
|
|
|
static inline struct bkey_i *bch2_bkey_make_mut_noupdate(struct btree_trans *trans, struct bkey_s_c k)
|
2023-05-01 08:58:59 +08:00
|
|
|
{
|
2023-05-01 07:21:06 +08:00
|
|
|
return __bch2_bkey_make_mut_noupdate(trans, k, 0, 0);
|
2023-04-28 11:48:33 +08:00
|
|
|
}
|
2023-05-01 08:58:59 +08:00
|
|
|
|
2023-05-01 07:21:06 +08:00
|
|
|
#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,
|
2023-06-27 06:36:24 +08:00
|
|
|
struct bkey_s_c *k, unsigned flags,
|
2023-05-01 07:21:06 +08:00
|
|
|
unsigned type, unsigned min_bytes)
|
|
|
|
{
|
2023-06-27 06:36:24 +08:00
|
|
|
struct bkey_i *mut = __bch2_bkey_make_mut_noupdate(trans, *k, type, min_bytes);
|
2023-05-01 07:21:06 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (IS_ERR(mut))
|
|
|
|
return mut;
|
|
|
|
|
|
|
|
ret = bch2_trans_update(trans, iter, mut, flags);
|
|
|
|
if (ret)
|
|
|
|
return ERR_PTR(ret);
|
2023-06-27 06:36:24 +08:00
|
|
|
|
|
|
|
*k = bkey_i_to_s_c(mut);
|
2023-05-01 07:21:06 +08:00
|
|
|
return mut;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct bkey_i *bch2_bkey_make_mut(struct btree_trans *trans, struct btree_iter *iter,
|
2023-06-27 06:36:24 +08:00
|
|
|
struct bkey_s_c *k, unsigned flags)
|
2023-05-01 07:21:06 +08:00
|
|
|
{
|
|
|
|
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,\
|
2023-04-28 11:48:33 +08:00
|
|
|
KEY_TYPE_##_type, sizeof(struct bkey_i_##_type)))
|
|
|
|
|
2023-05-01 06:46:24 +08:00
|
|
|
static inline struct bkey_i *__bch2_bkey_get_mut_noupdate(struct btree_trans *trans,
|
2023-04-28 11:48:33 +08:00
|
|
|
struct btree_iter *iter,
|
|
|
|
unsigned btree_id, struct bpos pos,
|
|
|
|
unsigned flags, unsigned type, unsigned min_bytes)
|
|
|
|
{
|
|
|
|
struct bkey_s_c k = __bch2_bkey_get_iter(trans, iter,
|
2024-04-08 06:05:34 +08:00
|
|
|
btree_id, pos, flags|BTREE_ITER_intent, type);
|
2023-08-08 00:04:05 +08:00
|
|
|
struct bkey_i *ret = IS_ERR(k.k)
|
2023-05-01 08:58:59 +08:00
|
|
|
? ERR_CAST(k.k)
|
2023-05-01 07:21:06 +08:00
|
|
|
: __bch2_bkey_make_mut_noupdate(trans, k, 0, min_bytes);
|
2023-08-08 00:04:05 +08:00
|
|
|
if (IS_ERR(ret))
|
2023-04-28 11:48:33 +08:00
|
|
|
bch2_trans_iter_exit(trans, iter);
|
|
|
|
return ret;
|
2023-05-01 08:58:59 +08:00
|
|
|
}
|
|
|
|
|
2023-05-01 06:46:24 +08:00
|
|
|
static inline struct bkey_i *bch2_bkey_get_mut_noupdate(struct btree_trans *trans,
|
|
|
|
struct btree_iter *iter,
|
|
|
|
unsigned btree_id, struct bpos pos,
|
|
|
|
unsigned flags)
|
|
|
|
{
|
|
|
|
return __bch2_bkey_get_mut_noupdate(trans, iter, btree_id, pos, flags, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct bkey_i *__bch2_bkey_get_mut(struct btree_trans *trans,
|
|
|
|
struct btree_iter *iter,
|
|
|
|
unsigned btree_id, struct bpos pos,
|
|
|
|
unsigned flags, unsigned type, unsigned min_bytes)
|
|
|
|
{
|
|
|
|
struct bkey_i *mut = __bch2_bkey_get_mut_noupdate(trans, iter,
|
2024-04-08 06:05:34 +08:00
|
|
|
btree_id, pos, flags|BTREE_ITER_intent, type, min_bytes);
|
2023-05-01 06:46:24 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (IS_ERR(mut))
|
|
|
|
return mut;
|
|
|
|
|
|
|
|
ret = bch2_trans_update(trans, iter, mut, flags);
|
|
|
|
if (ret) {
|
|
|
|
bch2_trans_iter_exit(trans, iter);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mut;
|
|
|
|
}
|
|
|
|
|
2023-04-28 11:48:33 +08:00
|
|
|
static inline struct bkey_i *bch2_bkey_get_mut_minsize(struct btree_trans *trans,
|
|
|
|
struct btree_iter *iter,
|
|
|
|
unsigned btree_id, struct bpos pos,
|
|
|
|
unsigned flags, unsigned min_bytes)
|
|
|
|
{
|
|
|
|
return __bch2_bkey_get_mut(trans, iter, btree_id, pos, flags, 0, min_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct bkey_i *bch2_bkey_get_mut(struct btree_trans *trans,
|
|
|
|
struct btree_iter *iter,
|
|
|
|
unsigned btree_id, struct bpos pos,
|
|
|
|
unsigned flags)
|
|
|
|
{
|
2023-05-01 06:46:24 +08:00
|
|
|
return __bch2_bkey_get_mut(trans, iter, btree_id, pos, flags, 0, 0);
|
2023-04-28 11:48:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define bch2_bkey_get_mut_typed(_trans, _iter, _btree_id, _pos, _flags, _type)\
|
|
|
|
bkey_i_to_##_type(__bch2_bkey_get_mut(_trans, _iter, \
|
|
|
|
_btree_id, _pos, _flags, \
|
|
|
|
KEY_TYPE_##_type, sizeof(struct bkey_i_##_type)))
|
|
|
|
|
|
|
|
static inline struct bkey_i *__bch2_bkey_alloc(struct btree_trans *trans, struct btree_iter *iter,
|
2023-05-01 06:59:28 +08:00
|
|
|
unsigned flags, unsigned type, unsigned val_size)
|
2023-04-28 11:48:33 +08:00
|
|
|
{
|
|
|
|
struct bkey_i *k = bch2_trans_kmalloc(trans, sizeof(*k) + val_size);
|
2023-05-01 06:59:28 +08:00
|
|
|
int ret;
|
2023-04-28 11:48:33 +08:00
|
|
|
|
2023-05-01 06:59:28 +08:00
|
|
|
if (IS_ERR(k))
|
|
|
|
return k;
|
|
|
|
|
|
|
|
bkey_init(&k->k);
|
|
|
|
k->k.p = iter->pos;
|
|
|
|
k->k.type = type;
|
|
|
|
set_bkey_val_bytes(&k->k, val_size);
|
2023-04-28 11:48:33 +08:00
|
|
|
|
2023-05-01 06:59:28 +08:00
|
|
|
ret = bch2_trans_update(trans, iter, k, flags);
|
|
|
|
if (unlikely(ret))
|
|
|
|
return ERR_PTR(ret);
|
2023-04-28 11:48:33 +08:00
|
|
|
return k;
|
|
|
|
}
|
2023-05-01 08:58:59 +08:00
|
|
|
|
2023-05-01 06:59:28 +08:00
|
|
|
#define bch2_bkey_alloc(_trans, _iter, _flags, _type) \
|
|
|
|
bkey_i_to_##_type(__bch2_bkey_alloc(_trans, _iter, _flags, \
|
2023-04-28 11:48:33 +08:00
|
|
|
KEY_TYPE_##_type, sizeof(struct bch_##_type)))
|
2023-05-01 08:58:59 +08:00
|
|
|
|
2017-03-17 14:18:50 +08:00
|
|
|
#endif /* _BCACHEFS_BTREE_UPDATE_H */
|