1 #ifndef _BCACHEFS_BTREE_UPDATE_H
2 #define _BCACHEFS_BTREE_UPDATE_H
4 #include "btree_iter.h"
11 void bch2_btree_node_lock_for_insert(struct bch_fs *, struct btree *,
13 bool bch2_btree_bset_insert_key(struct btree_iter *, struct btree *,
14 struct btree_node_iter *, struct bkey_i *);
15 void bch2_btree_journal_key(struct btree_insert *trans, struct btree_iter *,
18 /* Normal update interface: */
22 struct disk_reservation *disk_res;
23 struct journal_res journal_res;
25 struct extent_insert_hook *hook;
30 struct btree_insert_entry {
31 struct btree_iter *iter;
35 * true if entire key was inserted - can only be false for
42 int __bch2_btree_insert_at(struct btree_insert *);
44 #define _TENTH_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
45 #define COUNT_ARGS(...) _TENTH_ARG(__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1)
47 #define BTREE_INSERT_ENTRY(_iter, _k) \
48 ((struct btree_insert_entry) { \
54 #define BTREE_INSERT_ENTRY_EXTRA_RES(_iter, _k, _extra) \
55 ((struct btree_insert_entry) { \
58 .extra_res = (_extra), \
63 * bch_btree_insert_at - insert one or more keys at iterator positions
64 * @iter: btree iterator
65 * @insert_key: key to insert
66 * @disk_res: disk reservation
67 * @hook: extent insert callback
70 * -EINTR: locking changed, this function should be called again. Only returned
71 * if passed BTREE_INSERT_ATOMIC.
72 * -EROFS: filesystem read only
73 * -EIO: journal or btree node IO error
75 #define bch2_btree_insert_at(_c, _disk_res, _hook, \
76 _journal_seq, _flags, ...) \
77 __bch2_btree_insert_at(&(struct btree_insert) { \
79 .disk_res = (_disk_res), \
80 .journal_seq = (_journal_seq), \
83 .nr = COUNT_ARGS(__VA_ARGS__), \
84 .entries = (struct btree_insert_entry[]) { \
89 * Don't drop/retake locks: instead return -EINTR if need to upgrade to intent
90 * locks, -EAGAIN if need to wait on btree reserve
92 #define BTREE_INSERT_ATOMIC (1 << 0)
94 /* Don't check for -ENOSPC: */
95 #define BTREE_INSERT_NOFAIL (1 << 1)
97 /* for copygc, or when merging btree nodes */
98 #define BTREE_INSERT_USE_RESERVE (1 << 2)
99 #define BTREE_INSERT_USE_ALLOC_RESERVE (1 << 3)
102 * Insert is for journal replay: don't get journal reservations, or mark extents
105 #define BTREE_INSERT_JOURNAL_REPLAY (1 << 4)
107 /* Don't block on allocation failure (for new btree nodes: */
108 #define BTREE_INSERT_NOWAIT (1 << 5)
109 #define BTREE_INSERT_GC_LOCK_HELD (1 << 6)
111 #define BCH_HASH_SET_MUST_CREATE (1 << 7)
112 #define BCH_HASH_SET_MUST_REPLACE (1 << 8)
114 int bch2_btree_delete_at(struct btree_iter *, unsigned);
116 int bch2_btree_insert_list_at(struct btree_iter *, struct keylist *,
117 struct disk_reservation *,
118 struct extent_insert_hook *, u64 *, unsigned);
120 int bch2_btree_insert(struct bch_fs *, enum btree_id, struct bkey_i *,
121 struct disk_reservation *,
122 struct extent_insert_hook *, u64 *, int flags);
123 int bch2_btree_update(struct bch_fs *, enum btree_id,
124 struct bkey_i *, u64 *);
126 int bch2_btree_delete_range(struct bch_fs *, enum btree_id,
127 struct bpos, struct bpos, struct bversion,
128 struct disk_reservation *,
129 struct extent_insert_hook *, u64 *);
131 int bch2_btree_node_rewrite(struct bch_fs *c, struct btree_iter *,
133 int bch2_btree_node_update_key(struct bch_fs *, struct btree *,
134 struct bkey_i_extent *);
136 #endif /* _BCACHEFS_BTREE_UPDATE_H */