From 65bcd6579df322d0c6216a534c65ee41eda2b801 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 28 Mar 2021 20:56:25 -0400 Subject: [PATCH] buckets.c fixups XXX squash Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- fs/bcachefs/buckets.c | 89 +++++++++++++++++++------------------------ fs/bcachefs/buckets.h | 2 - 2 files changed, 40 insertions(+), 51 deletions(-) diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index df839021fd3d..88deb48a3a37 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -273,10 +273,9 @@ retry: ret->online_reserved = percpu_u64_get(c->online_reserved); - u64s = fs_usage_u64s(c); do { seq = read_seqcount_begin(&c->usage_lock); - memcpy(ret, c->usage_base, u64s * sizeof(u64)); + memcpy(&ret->u, c->usage_base, u64s * sizeof(u64)); for (i = 0; i < ARRAY_SIZE(c->usage); i++) acc_u64s_percpu((u64 *) &ret->u, (u64 __percpu *) c->usage[i], u64s); } while (read_seqcount_retry(&c->usage_lock, seq)); @@ -439,45 +438,6 @@ static bool bucket_became_unavailable(struct bucket_mark old, !is_available_bucket(new); } -int bch2_fs_usage_apply(struct bch_fs *c, - struct bch_fs_usage_online *src, - struct disk_reservation *disk_res, - unsigned journal_seq) -{ - struct bch_fs_usage *dst = fs_usage_ptr(c, journal_seq, false); - s64 added = src->u.data + src->u.reserved; - s64 should_not_have_added; - int ret = 0; - - percpu_rwsem_assert_held(&c->mark_lock); - - /* - * Not allowed to reduce sectors_available except by getting a - * reservation: - */ - should_not_have_added = added - (s64) (disk_res ? disk_res->sectors : 0); - if (WARN_ONCE(should_not_have_added > 0, - "disk usage increased by %lli more than reservation of %llu", - added, disk_res ? disk_res->sectors : 0)) { - atomic64_sub(should_not_have_added, &c->sectors_available); - added -= should_not_have_added; - ret = -1; - } - - if (added > 0) { - disk_res->sectors -= added; - src->online_reserved -= added; - } - - this_cpu_add(*c->online_reserved, src->online_reserved); - - preempt_disable(); - acc_u64s((u64 *) dst, (u64 *) &src->u, fs_usage_u64s(c)); - preempt_enable(); - - return ret; -} - static inline void account_bucket(struct bch_fs_usage *fs_usage, struct bch_dev_usage *dev_usage, enum bch_data_type type, @@ -672,7 +632,6 @@ static int __bch2_mark_alloc_bucket(struct bch_fs *c, struct bch_dev *ca, size_t b, bool owned_by_allocator, bool gc) { - struct bch_fs_usage *fs_usage = fs_usage_ptr(c, 0, gc); struct bucket *g = __bucket(ca, b, gc); struct bucket_mark old, new; @@ -680,13 +639,6 @@ static int __bch2_mark_alloc_bucket(struct bch_fs *c, struct bch_dev *ca, new.owned_by_allocator = owned_by_allocator; })); - /* - * XXX: this is wrong, this means we'll be doing updates to the percpu - * buckets_alloc counter that don't have an open journal buffer and - * we'll race with the machinery that accumulates that to ca->usage_base - */ - bch2_dev_usage_update(c, ca, fs_usage, old, new, 0, gc); - BUG_ON(!gc && !owned_by_allocator && !old.owned_by_allocator); @@ -1435,6 +1387,45 @@ int bch2_mark_update(struct btree_trans *trans, return ret; } +static int bch2_fs_usage_apply(struct bch_fs *c, + struct bch_fs_usage_online *src, + struct disk_reservation *disk_res, + unsigned journal_seq) +{ + struct bch_fs_usage *dst = fs_usage_ptr(c, journal_seq, false); + s64 added = src->u.data + src->u.reserved; + s64 should_not_have_added; + int ret = 0; + + percpu_rwsem_assert_held(&c->mark_lock); + + /* + * Not allowed to reduce sectors_available except by getting a + * reservation: + */ + should_not_have_added = added - (s64) (disk_res ? disk_res->sectors : 0); + if (WARN_ONCE(should_not_have_added > 0, + "disk usage increased by %lli more than reservation of %llu", + added, disk_res ? disk_res->sectors : 0)) { + atomic64_sub(should_not_have_added, &c->sectors_available); + added -= should_not_have_added; + ret = -1; + } + + if (added > 0) { + disk_res->sectors -= added; + src->online_reserved -= added; + } + + this_cpu_add(*c->online_reserved, src->online_reserved); + + preempt_disable(); + acc_u64s((u64 *) dst, (u64 *) &src->u, fs_usage_u64s(c)); + preempt_enable(); + + return ret; +} + void bch2_trans_fs_usage_apply(struct btree_trans *trans, struct bch_fs_usage_online *fs_usage) { diff --git a/fs/bcachefs/buckets.h b/fs/bcachefs/buckets.h index e53cee27a720..af8cb74d71e0 100644 --- a/fs/bcachefs/buckets.h +++ b/fs/bcachefs/buckets.h @@ -246,8 +246,6 @@ void bch2_mark_metadata_bucket(struct bch_fs *, struct bch_dev *, int bch2_mark_key(struct bch_fs *, struct bkey_s_c, unsigned, s64, struct bch_fs_usage *, u64, unsigned); -int bch2_fs_usage_apply(struct bch_fs *, struct bch_fs_usage_online *, - struct disk_reservation *, unsigned); int bch2_mark_update(struct btree_trans *, struct btree_iter *, struct bkey_i *, struct bch_fs_usage *, unsigned);