bcachefs: move: convert to bbpos
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
633169035a
commit
d5eade9345
@ -2,22 +2,10 @@
|
|||||||
#ifndef _BCACHEFS_BBPOS_H
|
#ifndef _BCACHEFS_BBPOS_H
|
||||||
#define _BCACHEFS_BBPOS_H
|
#define _BCACHEFS_BBPOS_H
|
||||||
|
|
||||||
|
#include "bbpos_types.h"
|
||||||
#include "bkey_methods.h"
|
#include "bkey_methods.h"
|
||||||
#include "btree_cache.h"
|
#include "btree_cache.h"
|
||||||
|
|
||||||
struct bbpos {
|
|
||||||
enum btree_id btree;
|
|
||||||
struct bpos pos;
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline struct bbpos BBPOS(enum btree_id btree, struct bpos pos)
|
|
||||||
{
|
|
||||||
return (struct bbpos) { btree, pos };
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BBPOS_MIN BBPOS(0, POS_MIN)
|
|
||||||
#define BBPOS_MAX BBPOS(BTREE_ID_NR - 1, POS_MAX)
|
|
||||||
|
|
||||||
static inline int bbpos_cmp(struct bbpos l, struct bbpos r)
|
static inline int bbpos_cmp(struct bbpos l, struct bbpos r)
|
||||||
{
|
{
|
||||||
return cmp_int(l.btree, r.btree) ?: bpos_cmp(l.pos, r.pos);
|
return cmp_int(l.btree, r.btree) ?: bpos_cmp(l.pos, r.pos);
|
||||||
|
|||||||
18
fs/bcachefs/bbpos_types.h
Normal file
18
fs/bcachefs/bbpos_types.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-2.0 */
|
||||||
|
#ifndef _BCACHEFS_BBPOS_TYPES_H
|
||||||
|
#define _BCACHEFS_BBPOS_TYPES_H
|
||||||
|
|
||||||
|
struct bbpos {
|
||||||
|
enum btree_id btree;
|
||||||
|
struct bpos pos;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline struct bbpos BBPOS(enum btree_id btree, struct bpos pos)
|
||||||
|
{
|
||||||
|
return (struct bbpos) { btree, pos };
|
||||||
|
}
|
||||||
|
|
||||||
|
#define BBPOS_MIN BBPOS(0, POS_MIN)
|
||||||
|
#define BBPOS_MAX BBPOS(BTREE_ID_NR - 1, POS_MAX)
|
||||||
|
|
||||||
|
#endif /* _BCACHEFS_BBPOS_TYPES_H */
|
||||||
@ -332,8 +332,8 @@ static ssize_t bch2_data_job_read(struct file *file, char __user *buf,
|
|||||||
struct bch_ioctl_data_event e = {
|
struct bch_ioctl_data_event e = {
|
||||||
.type = BCH_DATA_EVENT_PROGRESS,
|
.type = BCH_DATA_EVENT_PROGRESS,
|
||||||
.p.data_type = ctx->stats.data_type,
|
.p.data_type = ctx->stats.data_type,
|
||||||
.p.btree_id = ctx->stats.btree_id,
|
.p.btree_id = ctx->stats.pos.btree,
|
||||||
.p.pos = ctx->stats.pos,
|
.p.pos = ctx->stats.pos.pos,
|
||||||
.p.sectors_done = atomic64_read(&ctx->stats.sectors_seen),
|
.p.sectors_done = atomic64_read(&ctx->stats.sectors_seen),
|
||||||
.p.sectors_total = bch2_fs_usage_read_short(c).used,
|
.p.sectors_total = bch2_fs_usage_read_short(c).used,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -281,11 +281,11 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
nowork:
|
nowork:
|
||||||
if (m->ctxt && m->ctxt->stats) {
|
if (m->stats && m->stats) {
|
||||||
BUG_ON(k.k->p.offset <= iter.pos.offset);
|
BUG_ON(k.k->p.offset <= iter.pos.offset);
|
||||||
atomic64_inc(&m->ctxt->stats->keys_raced);
|
atomic64_inc(&m->stats->keys_raced);
|
||||||
atomic64_add(k.k->p.offset - iter.pos.offset,
|
atomic64_add(k.k->p.offset - iter.pos.offset,
|
||||||
&m->ctxt->stats->sectors_raced);
|
&m->stats->sectors_raced);
|
||||||
}
|
}
|
||||||
|
|
||||||
this_cpu_inc(c->counters[BCH_COUNTER_move_extent_fail]);
|
this_cpu_inc(c->counters[BCH_COUNTER_move_extent_fail]);
|
||||||
@ -439,6 +439,8 @@ int bch2_data_update_init(struct btree_trans *trans,
|
|||||||
bch2_bkey_buf_reassemble(&m->k, c, k);
|
bch2_bkey_buf_reassemble(&m->k, c, k);
|
||||||
m->btree_id = btree_id;
|
m->btree_id = btree_id;
|
||||||
m->data_opts = data_opts;
|
m->data_opts = data_opts;
|
||||||
|
m->ctxt = ctxt;
|
||||||
|
m->stats = ctxt->stats;
|
||||||
|
|
||||||
bch2_write_op_init(&m->op, c, io_opts);
|
bch2_write_op_init(&m->op, c, io_opts);
|
||||||
m->op.pos = bkey_start_pos(k.k);
|
m->op.pos = bkey_start_pos(k.k);
|
||||||
|
|||||||
@ -23,6 +23,7 @@ struct data_update {
|
|||||||
struct bkey_buf k;
|
struct bkey_buf k;
|
||||||
struct data_update_opts data_opts;
|
struct data_update_opts data_opts;
|
||||||
struct moving_context *ctxt;
|
struct moving_context *ctxt;
|
||||||
|
struct bch_move_stats *stats;
|
||||||
struct bch_write_op op;
|
struct bch_write_op op;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -367,7 +367,6 @@ int bch2_move_extent(struct moving_context *ctxt,
|
|||||||
|
|
||||||
BUG_ON(ret);
|
BUG_ON(ret);
|
||||||
|
|
||||||
io->write.ctxt = ctxt;
|
|
||||||
io->write.op.end_io = move_write_done;
|
io->write.op.end_io = move_write_done;
|
||||||
|
|
||||||
if (ctxt->rate)
|
if (ctxt->rate)
|
||||||
@ -567,8 +566,7 @@ static int bch2_move_data_btree(struct moving_context *ctxt,
|
|||||||
|
|
||||||
if (ctxt->stats) {
|
if (ctxt->stats) {
|
||||||
ctxt->stats->data_type = BCH_DATA_user;
|
ctxt->stats->data_type = BCH_DATA_user;
|
||||||
ctxt->stats->btree_id = btree_id;
|
ctxt->stats->pos = BBPOS(btree_id, start);
|
||||||
ctxt->stats->pos = start;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bch2_trans_iter_init(trans, &iter, btree_id, start,
|
bch2_trans_iter_init(trans, &iter, btree_id, start,
|
||||||
@ -595,7 +593,7 @@ static int bch2_move_data_btree(struct moving_context *ctxt,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
if (ctxt->stats)
|
if (ctxt->stats)
|
||||||
ctxt->stats->pos = iter.pos;
|
ctxt->stats->pos = BBPOS(iter.btree_id, iter.pos);
|
||||||
|
|
||||||
if (!bkey_extent_is_direct_data(k.k))
|
if (!bkey_extent_is_direct_data(k.k))
|
||||||
goto next_nondata;
|
goto next_nondata;
|
||||||
@ -656,7 +654,7 @@ int __bch2_move_data(struct moving_context *ctxt,
|
|||||||
for (id = start.btree;
|
for (id = start.btree;
|
||||||
id <= min_t(unsigned, end.btree, btree_id_nr_alive(c) - 1);
|
id <= min_t(unsigned, end.btree, btree_id_nr_alive(c) - 1);
|
||||||
id++) {
|
id++) {
|
||||||
ctxt->stats->btree_id = id;
|
ctxt->stats->pos = BBPOS(id, POS_MIN);
|
||||||
|
|
||||||
if (!btree_type_has_ptrs(id) ||
|
if (!btree_type_has_ptrs(id) ||
|
||||||
!bch2_btree_id_root(c, id)->b)
|
!bch2_btree_id_root(c, id)->b)
|
||||||
@ -894,7 +892,7 @@ static int bch2_move_btree(struct bch_fs *c,
|
|||||||
for (id = start_btree_id;
|
for (id = start_btree_id;
|
||||||
id <= min_t(unsigned, end_btree_id, btree_id_nr_alive(c) - 1);
|
id <= min_t(unsigned, end_btree_id, btree_id_nr_alive(c) - 1);
|
||||||
id++) {
|
id++) {
|
||||||
stats->btree_id = id;
|
stats->pos = BBPOS(id, POS_MIN);
|
||||||
|
|
||||||
if (!bch2_btree_id_root(c, id)->b)
|
if (!bch2_btree_id_root(c, id)->b)
|
||||||
continue;
|
continue;
|
||||||
@ -913,7 +911,7 @@ static int bch2_move_btree(struct bch_fs *c,
|
|||||||
bpos_cmp(b->key.k.p, end_pos)) > 0)
|
bpos_cmp(b->key.k.p, end_pos)) > 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
stats->pos = iter.pos;
|
stats->pos = BBPOS(iter.btree_id, iter.pos);
|
||||||
|
|
||||||
if (!pred(c, arg, b, &io_opts, &data_opts))
|
if (!pred(c, arg, b, &io_opts, &data_opts))
|
||||||
goto next;
|
goto next;
|
||||||
@ -1139,10 +1137,9 @@ static void bch2_moving_ctxt_to_text(struct printbuf *out, struct bch_fs *c, str
|
|||||||
prt_printf(out, "%s (%ps):", stats->name, ctxt->fn);
|
prt_printf(out, "%s (%ps):", stats->name, ctxt->fn);
|
||||||
prt_newline(out);
|
prt_newline(out);
|
||||||
|
|
||||||
prt_printf(out, " data type %s btree_id %s position: ",
|
prt_printf(out, " data type %s position: ",
|
||||||
bch2_data_types[stats->data_type],
|
bch2_data_types[stats->data_type]);
|
||||||
bch2_btree_id_str(stats->btree_id));
|
bch2_bbpos_to_text(out, stats->pos);
|
||||||
bch2_bpos_to_text(out, stats->pos);
|
|
||||||
prt_newline(out);
|
prt_newline(out);
|
||||||
printbuf_indent_add(out, 2);
|
printbuf_indent_add(out, 2);
|
||||||
|
|
||||||
|
|||||||
@ -2,10 +2,11 @@
|
|||||||
#ifndef _BCACHEFS_MOVE_TYPES_H
|
#ifndef _BCACHEFS_MOVE_TYPES_H
|
||||||
#define _BCACHEFS_MOVE_TYPES_H
|
#define _BCACHEFS_MOVE_TYPES_H
|
||||||
|
|
||||||
|
#include "bbpos_types.h"
|
||||||
|
|
||||||
struct bch_move_stats {
|
struct bch_move_stats {
|
||||||
enum bch_data_type data_type;
|
enum bch_data_type data_type;
|
||||||
enum btree_id btree_id;
|
struct bbpos pos;
|
||||||
struct bpos pos;
|
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
char name[32];
|
char name[32];
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user