Update bcachefs sources to 4ed63a3241 bcachefs: Trust in memory bucket mark

This commit is contained in:
Kent Overstreet 2019-08-27 17:46:09 -04:00
parent cc41f52bcc
commit c8322ce68c
4 changed files with 29 additions and 27 deletions

View File

@ -1 +1 @@
14f68409bec43faff9d7480632488def385e0638 4ed63a3241fa1e6d7610607be033ef08bef1a43e

View File

@ -205,20 +205,6 @@ void bch2_alloc_to_text(struct printbuf *out, struct bch_fs *c,
get_alloc_field(a.v, &d, i)); get_alloc_field(a.v, &d, i));
} }
static inline struct bkey_alloc_unpacked
alloc_mem_to_key(struct bucket *g, struct bucket_mark m)
{
return (struct bkey_alloc_unpacked) {
.gen = m.gen,
.oldest_gen = g->oldest_gen,
.data_type = m.data_type,
.dirty_sectors = m.dirty_sectors,
.cached_sectors = m.cached_sectors,
.read_time = g->io_time[READ],
.write_time = g->io_time[WRITE],
};
}
int bch2_alloc_read(struct bch_fs *c, struct journal_keys *journal_keys) int bch2_alloc_read(struct bch_fs *c, struct journal_keys *journal_keys)
{ {
struct btree_trans trans; struct btree_trans trans;

View File

@ -17,6 +17,20 @@ struct bkey_alloc_unpacked bch2_alloc_unpack(struct bkey_s_c);
void bch2_alloc_pack(struct bkey_i_alloc *, void bch2_alloc_pack(struct bkey_i_alloc *,
const struct bkey_alloc_unpacked); const struct bkey_alloc_unpacked);
static inline struct bkey_alloc_unpacked
alloc_mem_to_key(struct bucket *g, struct bucket_mark m)
{
return (struct bkey_alloc_unpacked) {
.gen = m.gen,
.oldest_gen = g->oldest_gen,
.data_type = m.data_type,
.dirty_sectors = m.dirty_sectors,
.cached_sectors = m.cached_sectors,
.read_time = g->io_time[READ],
.write_time = g->io_time[WRITE],
};
}
#define ALLOC_SCAN_BATCH(ca) max_t(size_t, 1, (ca)->mi.nbuckets >> 9) #define ALLOC_SCAN_BATCH(ca) max_t(size_t, 1, (ca)->mi.nbuckets >> 9)
const char *bch2_alloc_invalid(const struct bch_fs *, struct bkey_s_c); const char *bch2_alloc_invalid(const struct bch_fs *, struct bkey_s_c);

View File

@ -1361,7 +1361,7 @@ static int trans_get_key(struct btree_trans *trans,
: !bkey_cmp(pos, i->iter->pos))) { : !bkey_cmp(pos, i->iter->pos))) {
*iter = i->iter; *iter = i->iter;
*k = bkey_i_to_s_c(i->k); *k = bkey_i_to_s_c(i->k);
return 0; return 1;
} }
*iter = __bch2_trans_get_iter(trans, btree_id, pos, *iter = __bch2_trans_get_iter(trans, btree_id, pos,
@ -1416,6 +1416,8 @@ static int bch2_trans_mark_pointer(struct btree_trans *trans,
struct bch_dev *ca = bch_dev_bkey_exists(c, p.ptr.dev); struct bch_dev *ca = bch_dev_bkey_exists(c, p.ptr.dev);
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bucket *g;
struct bucket_mark m;
struct bkey_alloc_unpacked u; struct bkey_alloc_unpacked u;
struct bkey_i_alloc *a; struct bkey_i_alloc *a;
bool overflow; bool overflow;
@ -1424,19 +1426,19 @@ static int bch2_trans_mark_pointer(struct btree_trans *trans,
ret = trans_get_key(trans, BTREE_ID_ALLOC, ret = trans_get_key(trans, BTREE_ID_ALLOC,
POS(p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr)), POS(p.ptr.dev, PTR_BUCKET_NR(ca, &p.ptr)),
&iter, &k); &iter, &k);
if (ret) if (ret < 0)
return ret; return ret;
if (k.k->type != KEY_TYPE_alloc) { if (!ret) {
bch_err_ratelimited(c, "pointer to nonexistent bucket %u:%zu", percpu_down_read(&c->mark_lock);
p.ptr.dev, g = bucket(ca, iter->pos.offset);
PTR_BUCKET_NR(ca, &p.ptr)); m = READ_ONCE(g->mark);
ret = -1; u = alloc_mem_to_key(g, m);
goto out; percpu_up_read(&c->mark_lock);
} else {
u = bch2_alloc_unpack(k);
} }
u = bch2_alloc_unpack(k);
if (gen_after(u.gen, p.ptr.gen)) { if (gen_after(u.gen, p.ptr.gen)) {
ret = 1; ret = 1;
goto out; goto out;
@ -1484,7 +1486,7 @@ static int bch2_trans_mark_stripe_ptr(struct btree_trans *trans,
int ret = 0; int ret = 0;
ret = trans_get_key(trans, BTREE_ID_EC, POS(0, p.idx), &iter, &k); ret = trans_get_key(trans, BTREE_ID_EC, POS(0, p.idx), &iter, &k);
if (ret) if (ret < 0)
return ret; return ret;
if (k.k->type != KEY_TYPE_stripe) { if (k.k->type != KEY_TYPE_stripe) {
@ -1599,7 +1601,7 @@ static int __bch2_trans_mark_reflink_p(struct btree_trans *trans,
ret = trans_get_key(trans, BTREE_ID_REFLINK, ret = trans_get_key(trans, BTREE_ID_REFLINK,
POS(0, idx), &iter, &k); POS(0, idx), &iter, &k);
if (ret) if (ret < 0)
return ret; return ret;
if (k.k->type != KEY_TYPE_reflink_v) { if (k.k->type != KEY_TYPE_reflink_v) {