mirror of
https://github.com/torvalds/linux.git
synced 2024-11-16 00:52:01 +00:00
bcachefs: Split out SPOS_MAX
Internal btree code really wants a POS_MAX with all fields ~0; external code more likely wants the snapshot field to be 0, because when we're passing it to bch2_trans_get_iter() it's used for the snapshot we're operating in, which should be 0 for most btrees that don't use snapshots. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
parent
41e633826a
commit
618b1c0e20
@ -152,7 +152,8 @@ static inline struct bpos SPOS(__u64 inode, __u64 offset, __u32 snapshot)
|
||||
}
|
||||
|
||||
#define POS_MIN SPOS(0, 0, 0)
|
||||
#define POS_MAX SPOS(KEY_INODE_MAX, KEY_OFFSET_MAX, KEY_SNAPSHOT_MAX)
|
||||
#define POS_MAX SPOS(KEY_INODE_MAX, KEY_OFFSET_MAX, 0)
|
||||
#define SPOS_MAX SPOS(KEY_INODE_MAX, KEY_OFFSET_MAX, KEY_SNAPSHOT_MAX)
|
||||
#define POS(_inode, _offset) SPOS(_inode, _offset, 0)
|
||||
|
||||
/* Empty placeholder struct, for container_of() */
|
||||
|
@ -962,7 +962,7 @@ static int bch2_gc_btree_init(struct bch_fs *c,
|
||||
goto fsck_err;
|
||||
}
|
||||
|
||||
if (mustfix_fsck_err_on(bpos_cmp(b->data->max_key, POS_MAX), c,
|
||||
if (mustfix_fsck_err_on(bpos_cmp(b->data->max_key, SPOS_MAX), c,
|
||||
"btree root with incorrect max_key: %s",
|
||||
(bch2_bpos_to_text(&PBUF(buf), b->data->max_key), buf))) {
|
||||
bch_err(c, "repair unimplemented");
|
||||
|
@ -87,7 +87,7 @@ static inline struct gc_pos gc_pos_btree_node(struct btree *b)
|
||||
*/
|
||||
static inline struct gc_pos gc_pos_btree_root(enum btree_id id)
|
||||
{
|
||||
return gc_pos_btree(id, POS_MAX, BTREE_MAX_DEPTH);
|
||||
return gc_pos_btree(id, SPOS_MAX, BTREE_MAX_DEPTH);
|
||||
}
|
||||
|
||||
static inline bool gc_visited(struct bch_fs *c, struct gc_pos pos)
|
||||
|
@ -1081,7 +1081,7 @@ static inline int btree_iter_lock_root(struct btree_iter *iter,
|
||||
}
|
||||
|
||||
lock_type = __btree_lock_want(iter, iter->level);
|
||||
if (unlikely(!btree_node_lock(b, POS_MAX, iter->level,
|
||||
if (unlikely(!btree_node_lock(b, SPOS_MAX, iter->level,
|
||||
iter, lock_type,
|
||||
lock_root_check_fn, rootp,
|
||||
trace_ip)))
|
||||
@ -1602,7 +1602,7 @@ out:
|
||||
inline bool bch2_btree_iter_advance(struct btree_iter *iter)
|
||||
{
|
||||
struct bpos pos = iter->k.p;
|
||||
bool ret = bpos_cmp(pos, POS_MAX) != 0;
|
||||
bool ret = bpos_cmp(pos, SPOS_MAX) != 0;
|
||||
|
||||
if (ret && !(iter->flags & BTREE_ITER_IS_EXTENTS))
|
||||
pos = bkey_successor(iter, pos);
|
||||
@ -1624,7 +1624,7 @@ inline bool bch2_btree_iter_rewind(struct btree_iter *iter)
|
||||
static inline bool btree_iter_set_pos_to_next_leaf(struct btree_iter *iter)
|
||||
{
|
||||
struct bpos next_pos = iter->l[0].b->key.k.p;
|
||||
bool ret = bpos_cmp(next_pos, POS_MAX) != 0;
|
||||
bool ret = bpos_cmp(next_pos, SPOS_MAX) != 0;
|
||||
|
||||
/*
|
||||
* Typically, we don't want to modify iter->pos here, since that
|
||||
@ -1634,7 +1634,7 @@ static inline bool btree_iter_set_pos_to_next_leaf(struct btree_iter *iter)
|
||||
if (ret)
|
||||
btree_iter_set_search_pos(iter, bpos_successor(next_pos));
|
||||
else
|
||||
bch2_btree_iter_set_pos(iter, POS_MAX);
|
||||
bch2_btree_iter_set_pos(iter, SPOS_MAX);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ static struct btree *__btree_root_alloc(struct btree_update *as, unsigned level)
|
||||
struct btree *b = bch2_btree_node_alloc(as, level);
|
||||
|
||||
btree_set_min(b, POS_MIN);
|
||||
btree_set_max(b, POS_MAX);
|
||||
btree_set_max(b, SPOS_MAX);
|
||||
b->data->format = bch2_btree_calc_format(b);
|
||||
|
||||
btree_node_set_format(b, b->data->format);
|
||||
@ -1590,7 +1590,7 @@ retry:
|
||||
b = iter->l[level].b;
|
||||
|
||||
if ((sib == btree_prev_sib && !bpos_cmp(b->data->min_key, POS_MIN)) ||
|
||||
(sib == btree_next_sib && !bpos_cmp(b->data->max_key, POS_MAX))) {
|
||||
(sib == btree_next_sib && !bpos_cmp(b->data->max_key, SPOS_MAX))) {
|
||||
b->sib_u64s[sib] = U16_MAX;
|
||||
goto out;
|
||||
}
|
||||
@ -2014,7 +2014,7 @@ void bch2_btree_root_alloc(struct bch_fs *c, enum btree_id id)
|
||||
b->c.btree_id = id;
|
||||
|
||||
bkey_btree_ptr_init(&b->key);
|
||||
b->key.k.p = POS_MAX;
|
||||
b->key.k.p = SPOS_MAX;
|
||||
*((u64 *) bkey_i_to_btree_ptr(&b->key)->v.start) = U64_MAX - id;
|
||||
|
||||
bch2_bset_init_first(b, &b->data->keys);
|
||||
@ -2022,7 +2022,7 @@ void bch2_btree_root_alloc(struct bch_fs *c, enum btree_id id)
|
||||
|
||||
b->data->flags = 0;
|
||||
btree_set_min(b, POS_MIN);
|
||||
btree_set_max(b, POS_MAX);
|
||||
btree_set_max(b, SPOS_MAX);
|
||||
b->data->format = bch2_btree_calc_format(b);
|
||||
btree_node_set_format(b, b->data->format);
|
||||
|
||||
|
@ -313,7 +313,7 @@ static ssize_t bch2_read_btree_formats(struct file *file, char __user *buf,
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (!i->size || !bpos_cmp(POS_MAX, i->from))
|
||||
if (!i->size || !bpos_cmp(SPOS_MAX, i->from))
|
||||
return i->ret;
|
||||
|
||||
bch2_trans_init(&trans, i->c, 0, 0);
|
||||
@ -329,7 +329,7 @@ static ssize_t bch2_read_btree_formats(struct file *file, char __user *buf,
|
||||
* can't easily correctly restart a btree node traversal across
|
||||
* all nodes, meh
|
||||
*/
|
||||
i->from = bpos_cmp(POS_MAX, b->key.k.p)
|
||||
i->from = bpos_cmp(SPOS_MAX, b->key.k.p)
|
||||
? bpos_successor(b->key.k.p)
|
||||
: b->key.k.p;
|
||||
|
||||
|
@ -769,7 +769,7 @@ static int bch2_move_btree(struct bch_fs *c,
|
||||
break;
|
||||
|
||||
if ((cmp_int(id, end_btree_id) ?:
|
||||
bkey_cmp(b->key.k.p, end_pos)) > 0)
|
||||
bpos_cmp(b->key.k.p, end_pos)) > 0)
|
||||
break;
|
||||
|
||||
stats->pos = iter->pos;
|
||||
@ -921,7 +921,7 @@ int bch2_scan_old_btree_nodes(struct bch_fs *c, struct bch_move_stats *stats)
|
||||
|
||||
ret = bch2_move_btree(c,
|
||||
0, POS_MIN,
|
||||
BTREE_ID_NR, POS_MAX,
|
||||
BTREE_ID_NR, SPOS_MAX,
|
||||
rewrite_old_nodes_pred, c, stats);
|
||||
if (!ret) {
|
||||
mutex_lock(&c->sb_lock);
|
||||
|
Loading…
Reference in New Issue
Block a user