]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Convert bucket_alloc_ret to negative error codes
authorKent Overstreet <kent.overstreet@gmail.com>
Sun, 28 Nov 2021 18:42:05 +0000 (13:42 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:17 +0000 (17:09 -0400)
Start a new header, errcode.h, for bcachefs-private error codes - more
error codes will be converted later.

This patch just converts bucket_alloc_ret so that they can be mixed with
standard error codes and passed as ERR_PTR errors - the ec.c code was
doing this already, but incorrectly.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/alloc_foreground.c
fs/bcachefs/alloc_foreground.h
fs/bcachefs/bcachefs.h
fs/bcachefs/ec.c
fs/bcachefs/errcode.h [new file with mode: 0644]

index 6bf4140477a04c8b7bce6d2b07c783f0a3523bf6..e3fe4d7bbe21422023026758a7870adee5e231e4 100644 (file)
@@ -348,8 +348,7 @@ static void add_new_bucket(struct bch_fs *c,
        ob_push(c, ptrs, ob);
 }
 
-enum bucket_alloc_ret
-bch2_bucket_alloc_set(struct bch_fs *c,
+int bch2_bucket_alloc_set(struct bch_fs *c,
                      struct open_buckets *ptrs,
                      struct dev_stripe_state *stripe,
                      struct bch_devs_mask *devs_may_alloc,
@@ -363,7 +362,7 @@ bch2_bucket_alloc_set(struct bch_fs *c,
        struct dev_alloc_list devs_sorted =
                bch2_dev_alloc_list(c, stripe, devs_may_alloc);
        struct bch_dev *ca;
-       enum bucket_alloc_ret ret = INSUFFICIENT_DEVICES;
+       int ret = -INSUFFICIENT_DEVICES;
        unsigned i;
 
        BUG_ON(*nr_effective >= nr_replicas);
@@ -381,7 +380,7 @@ bch2_bucket_alloc_set(struct bch_fs *c,
                ob = bch2_bucket_alloc(c, ca, reserve,
                                flags & BUCKET_MAY_ALLOC_PARTIAL, cl);
                if (IS_ERR(ob)) {
-                       ret = -PTR_ERR(ob);
+                       ret = PTR_ERR(ob);
 
                        if (cl)
                                return ret;
@@ -394,7 +393,7 @@ bch2_bucket_alloc_set(struct bch_fs *c,
                bch2_dev_stripe_increment(ca, stripe);
 
                if (*nr_effective >= nr_replicas)
-                       return ALLOC_SUCCESS;
+                       return 0;
        }
 
        return ret;
@@ -408,8 +407,7 @@ bch2_bucket_alloc_set(struct bch_fs *c,
  * it's to a device we don't want:
  */
 
-static enum bucket_alloc_ret
-bucket_alloc_from_stripe(struct bch_fs *c,
+static int bucket_alloc_from_stripe(struct bch_fs *c,
                         struct open_buckets *ptrs,
                         struct write_point *wp,
                         struct bch_devs_mask *devs_may_alloc,
@@ -505,8 +503,7 @@ static void get_buckets_from_writepoint(struct bch_fs *c,
        wp->ptrs = ptrs_skip;
 }
 
-static enum bucket_alloc_ret
-open_bucket_add_buckets(struct bch_fs *c,
+static int open_bucket_add_buckets(struct bch_fs *c,
                        struct open_buckets *ptrs,
                        struct write_point *wp,
                        struct bch_devs_list *devs_have,
@@ -522,7 +519,7 @@ open_bucket_add_buckets(struct bch_fs *c,
        struct bch_devs_mask devs;
        struct open_bucket *ob;
        struct closure *cl = NULL;
-       enum bucket_alloc_ret ret;
+       int ret;
        unsigned i;
 
        rcu_read_lock();
@@ -550,8 +547,8 @@ open_bucket_add_buckets(struct bch_fs *c,
                                                 target, erasure_code,
                                                 nr_replicas, nr_effective,
                                                 have_cache, flags, _cl);
-                       if (ret == FREELIST_EMPTY ||
-                           ret == OPEN_BUCKETS_EMPTY)
+                       if (ret == -FREELIST_EMPTY ||
+                           ret == -OPEN_BUCKETS_EMPTY)
                                return ret;
                        if (*nr_effective >= nr_replicas)
                                return 0;
@@ -575,7 +572,7 @@ retry_blocking:
        ret = bch2_bucket_alloc_set(c, ptrs, &wp->stripe, &devs,
                                nr_replicas, nr_effective, have_cache,
                                reserve, flags, cl);
-       if (ret && ret != INSUFFICIENT_DEVICES && !cl && _cl) {
+       if (ret && ret != -INSUFFICIENT_DEVICES && !cl && _cl) {
                cl = _cl;
                goto retry_blocking;
        }
@@ -772,7 +769,7 @@ struct write_point *bch2_alloc_sectors_start(struct bch_fs *c,
        unsigned nr_effective, write_points_nr;
        unsigned ob_flags = 0;
        bool have_cache;
-       enum bucket_alloc_ret ret;
+       int ret;
        int i;
 
        if (!(flags & BCH_WRITE_ONLY_SPECIFIED_DEVS))
@@ -821,7 +818,7 @@ alloc_done:
        if (erasure_code && !ec_open_bucket(c, &ptrs))
                pr_debug("failed to get ec bucket: ret %u", ret);
 
-       if (ret == INSUFFICIENT_DEVICES &&
+       if (ret == -INSUFFICIENT_DEVICES &&
            nr_effective >= nr_replicas_required)
                ret = 0;
 
@@ -854,15 +851,15 @@ err:
 
        mutex_unlock(&wp->lock);
 
-       if (ret == FREELIST_EMPTY &&
+       if (ret == -FREELIST_EMPTY &&
            try_decrease_writepoints(c, write_points_nr))
                goto retry;
 
        switch (ret) {
-       case OPEN_BUCKETS_EMPTY:
-       case FREELIST_EMPTY:
+       case -OPEN_BUCKETS_EMPTY:
+       case -FREELIST_EMPTY:
                return cl ? ERR_PTR(-EAGAIN) : ERR_PTR(-ENOSPC);
-       case INSUFFICIENT_DEVICES:
+       case -INSUFFICIENT_DEVICES:
                return ERR_PTR(-EROFS);
        default:
                BUG();
index c658295cb8e09f375b5b416a222b14e3070fb779..2e81712ba8d1f727ab1d068df1505552a352d617 100644 (file)
@@ -12,13 +12,6 @@ struct bch_dev;
 struct bch_fs;
 struct bch_devs_List;
 
-enum bucket_alloc_ret {
-       ALLOC_SUCCESS,
-       OPEN_BUCKETS_EMPTY,
-       FREELIST_EMPTY,         /* Allocator thread not keeping up */
-       INSUFFICIENT_DEVICES,
-};
-
 struct dev_alloc_list {
        unsigned        nr;
        u8              devs[BCH_SB_MEMBERS_MAX];
@@ -98,8 +91,7 @@ static inline void bch2_open_bucket_get(struct bch_fs *c,
        }
 }
 
-enum bucket_alloc_ret
-bch2_bucket_alloc_set(struct bch_fs *, struct open_buckets *,
+int bch2_bucket_alloc_set(struct bch_fs *, struct open_buckets *,
                      struct dev_stripe_state *, struct bch_devs_mask *,
                      unsigned, unsigned *, bool *, enum alloc_reserve,
                      unsigned, struct closure *);
index 077d366961ff5b6671ba241af684620b72ba944d..4d3cfb64a6565d833204914204536898f7725dbf 100644 (file)
 #include <linux/zstd.h>
 
 #include "bcachefs_format.h"
+#include "errcode.h"
 #include "fifo.h"
 #include "opts.h"
 #include "util.h"
index bc8bb963ae43ed0dc9991486e0e0bae069f12261..9624cd5e5adabb9ed5c18345e5d648ef3c429526 100644 (file)
@@ -1272,16 +1272,15 @@ found:
        return h;
 }
 
-static enum bucket_alloc_ret
-new_stripe_alloc_buckets(struct bch_fs *c, struct ec_stripe_head *h,
-                        struct closure *cl)
+static int new_stripe_alloc_buckets(struct bch_fs *c, struct ec_stripe_head *h,
+                                   struct closure *cl)
 {
        struct bch_devs_mask devs = h->devs;
        struct open_bucket *ob;
        struct open_buckets buckets;
        unsigned i, j, nr_have_parity = 0, nr_have_data = 0;
        bool have_cache = true;
-       enum bucket_alloc_ret ret = ALLOC_SUCCESS;
+       int ret = 0;
 
        for (i = 0; i < h->s->new_stripe.key.v.nr_blocks; i++) {
                if (test_bit(i, h->s->blocks_gotten)) {
@@ -1516,7 +1515,7 @@ struct ec_stripe_head *bch2_ec_stripe_head_get(struct bch_fs *c,
 
 err:
        bch2_ec_stripe_head_put(c, h);
-       return ERR_PTR(-ret);
+       return ERR_PTR(ret);
 }
 
 void bch2_ec_stop_dev(struct bch_fs *c, struct bch_dev *ca)
diff --git a/fs/bcachefs/errcode.h b/fs/bcachefs/errcode.h
new file mode 100644 (file)
index 0000000..f7d1291
--- /dev/null
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _BCACHEFS_ERRCODE_H
+#define _BCACHEFS_ERRCODE_H
+
+enum {
+       /* Bucket allocator: */
+       OPEN_BUCKETS_EMPTY =    2048,
+       FREELIST_EMPTY,         /* Allocator thread not keeping up */
+       INSUFFICIENT_DEVICES,
+};
+
+#endif /* _BCACHFES_ERRCODE_H */