]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
buckets.c fixups XXX squash
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 29 Mar 2021 00:56:25 +0000 (20:56 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:58 +0000 (17:08 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/buckets.c
fs/bcachefs/buckets.h

index df839021fd3d2eda7ff83b47e23de24abff14b6b..88deb48a3a37464fe6ccb7931b3c3aa74de36367 100644 (file)
@@ -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)
 {
index e53cee27a720423979c180f2c8420ae62a1f9a20..af8cb74d71e0c59df7f4aeba26b23e11f7d8dba9 100644 (file)
@@ -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);