Commit fc6c01e2 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Convert bucket_alloc_ret to negative error codes

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: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent dcfc593f
...@@ -348,8 +348,7 @@ static void add_new_bucket(struct bch_fs *c, ...@@ -348,8 +348,7 @@ static void add_new_bucket(struct bch_fs *c,
ob_push(c, ptrs, ob); ob_push(c, ptrs, ob);
} }
enum bucket_alloc_ret int bch2_bucket_alloc_set(struct bch_fs *c,
bch2_bucket_alloc_set(struct bch_fs *c,
struct open_buckets *ptrs, struct open_buckets *ptrs,
struct dev_stripe_state *stripe, struct dev_stripe_state *stripe,
struct bch_devs_mask *devs_may_alloc, struct bch_devs_mask *devs_may_alloc,
...@@ -363,7 +362,7 @@ bch2_bucket_alloc_set(struct bch_fs *c, ...@@ -363,7 +362,7 @@ bch2_bucket_alloc_set(struct bch_fs *c,
struct dev_alloc_list devs_sorted = struct dev_alloc_list devs_sorted =
bch2_dev_alloc_list(c, stripe, devs_may_alloc); bch2_dev_alloc_list(c, stripe, devs_may_alloc);
struct bch_dev *ca; struct bch_dev *ca;
enum bucket_alloc_ret ret = INSUFFICIENT_DEVICES; int ret = -INSUFFICIENT_DEVICES;
unsigned i; unsigned i;
BUG_ON(*nr_effective >= nr_replicas); BUG_ON(*nr_effective >= nr_replicas);
...@@ -381,7 +380,7 @@ bch2_bucket_alloc_set(struct bch_fs *c, ...@@ -381,7 +380,7 @@ bch2_bucket_alloc_set(struct bch_fs *c,
ob = bch2_bucket_alloc(c, ca, reserve, ob = bch2_bucket_alloc(c, ca, reserve,
flags & BUCKET_MAY_ALLOC_PARTIAL, cl); flags & BUCKET_MAY_ALLOC_PARTIAL, cl);
if (IS_ERR(ob)) { if (IS_ERR(ob)) {
ret = -PTR_ERR(ob); ret = PTR_ERR(ob);
if (cl) if (cl)
return ret; return ret;
...@@ -394,7 +393,7 @@ bch2_bucket_alloc_set(struct bch_fs *c, ...@@ -394,7 +393,7 @@ bch2_bucket_alloc_set(struct bch_fs *c,
bch2_dev_stripe_increment(ca, stripe); bch2_dev_stripe_increment(ca, stripe);
if (*nr_effective >= nr_replicas) if (*nr_effective >= nr_replicas)
return ALLOC_SUCCESS; return 0;
} }
return ret; return ret;
...@@ -408,8 +407,7 @@ bch2_bucket_alloc_set(struct bch_fs *c, ...@@ -408,8 +407,7 @@ bch2_bucket_alloc_set(struct bch_fs *c,
* it's to a device we don't want: * it's to a device we don't want:
*/ */
static enum bucket_alloc_ret static int bucket_alloc_from_stripe(struct bch_fs *c,
bucket_alloc_from_stripe(struct bch_fs *c,
struct open_buckets *ptrs, struct open_buckets *ptrs,
struct write_point *wp, struct write_point *wp,
struct bch_devs_mask *devs_may_alloc, struct bch_devs_mask *devs_may_alloc,
...@@ -505,8 +503,7 @@ static void get_buckets_from_writepoint(struct bch_fs *c, ...@@ -505,8 +503,7 @@ static void get_buckets_from_writepoint(struct bch_fs *c,
wp->ptrs = ptrs_skip; wp->ptrs = ptrs_skip;
} }
static enum bucket_alloc_ret static int open_bucket_add_buckets(struct bch_fs *c,
open_bucket_add_buckets(struct bch_fs *c,
struct open_buckets *ptrs, struct open_buckets *ptrs,
struct write_point *wp, struct write_point *wp,
struct bch_devs_list *devs_have, struct bch_devs_list *devs_have,
...@@ -522,7 +519,7 @@ open_bucket_add_buckets(struct bch_fs *c, ...@@ -522,7 +519,7 @@ open_bucket_add_buckets(struct bch_fs *c,
struct bch_devs_mask devs; struct bch_devs_mask devs;
struct open_bucket *ob; struct open_bucket *ob;
struct closure *cl = NULL; struct closure *cl = NULL;
enum bucket_alloc_ret ret; int ret;
unsigned i; unsigned i;
rcu_read_lock(); rcu_read_lock();
...@@ -550,8 +547,8 @@ open_bucket_add_buckets(struct bch_fs *c, ...@@ -550,8 +547,8 @@ open_bucket_add_buckets(struct bch_fs *c,
target, erasure_code, target, erasure_code,
nr_replicas, nr_effective, nr_replicas, nr_effective,
have_cache, flags, _cl); have_cache, flags, _cl);
if (ret == FREELIST_EMPTY || if (ret == -FREELIST_EMPTY ||
ret == OPEN_BUCKETS_EMPTY) ret == -OPEN_BUCKETS_EMPTY)
return ret; return ret;
if (*nr_effective >= nr_replicas) if (*nr_effective >= nr_replicas)
return 0; return 0;
...@@ -575,7 +572,7 @@ open_bucket_add_buckets(struct bch_fs *c, ...@@ -575,7 +572,7 @@ open_bucket_add_buckets(struct bch_fs *c,
ret = bch2_bucket_alloc_set(c, ptrs, &wp->stripe, &devs, ret = bch2_bucket_alloc_set(c, ptrs, &wp->stripe, &devs,
nr_replicas, nr_effective, have_cache, nr_replicas, nr_effective, have_cache,
reserve, flags, cl); reserve, flags, cl);
if (ret && ret != INSUFFICIENT_DEVICES && !cl && _cl) { if (ret && ret != -INSUFFICIENT_DEVICES && !cl && _cl) {
cl = _cl; cl = _cl;
goto retry_blocking; goto retry_blocking;
} }
...@@ -772,7 +769,7 @@ struct write_point *bch2_alloc_sectors_start(struct bch_fs *c, ...@@ -772,7 +769,7 @@ struct write_point *bch2_alloc_sectors_start(struct bch_fs *c,
unsigned nr_effective, write_points_nr; unsigned nr_effective, write_points_nr;
unsigned ob_flags = 0; unsigned ob_flags = 0;
bool have_cache; bool have_cache;
enum bucket_alloc_ret ret; int ret;
int i; int i;
if (!(flags & BCH_WRITE_ONLY_SPECIFIED_DEVS)) if (!(flags & BCH_WRITE_ONLY_SPECIFIED_DEVS))
...@@ -821,7 +818,7 @@ struct write_point *bch2_alloc_sectors_start(struct bch_fs *c, ...@@ -821,7 +818,7 @@ struct write_point *bch2_alloc_sectors_start(struct bch_fs *c,
if (erasure_code && !ec_open_bucket(c, &ptrs)) if (erasure_code && !ec_open_bucket(c, &ptrs))
pr_debug("failed to get ec bucket: ret %u", ret); pr_debug("failed to get ec bucket: ret %u", ret);
if (ret == INSUFFICIENT_DEVICES && if (ret == -INSUFFICIENT_DEVICES &&
nr_effective >= nr_replicas_required) nr_effective >= nr_replicas_required)
ret = 0; ret = 0;
...@@ -854,15 +851,15 @@ struct write_point *bch2_alloc_sectors_start(struct bch_fs *c, ...@@ -854,15 +851,15 @@ struct write_point *bch2_alloc_sectors_start(struct bch_fs *c,
mutex_unlock(&wp->lock); mutex_unlock(&wp->lock);
if (ret == FREELIST_EMPTY && if (ret == -FREELIST_EMPTY &&
try_decrease_writepoints(c, write_points_nr)) try_decrease_writepoints(c, write_points_nr))
goto retry; goto retry;
switch (ret) { switch (ret) {
case OPEN_BUCKETS_EMPTY: case -OPEN_BUCKETS_EMPTY:
case FREELIST_EMPTY: case -FREELIST_EMPTY:
return cl ? ERR_PTR(-EAGAIN) : ERR_PTR(-ENOSPC); return cl ? ERR_PTR(-EAGAIN) : ERR_PTR(-ENOSPC);
case INSUFFICIENT_DEVICES: case -INSUFFICIENT_DEVICES:
return ERR_PTR(-EROFS); return ERR_PTR(-EROFS);
default: default:
BUG(); BUG();
......
...@@ -12,13 +12,6 @@ struct bch_dev; ...@@ -12,13 +12,6 @@ struct bch_dev;
struct bch_fs; struct bch_fs;
struct bch_devs_List; 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 { struct dev_alloc_list {
unsigned nr; unsigned nr;
u8 devs[BCH_SB_MEMBERS_MAX]; u8 devs[BCH_SB_MEMBERS_MAX];
...@@ -98,8 +91,7 @@ static inline void bch2_open_bucket_get(struct bch_fs *c, ...@@ -98,8 +91,7 @@ static inline void bch2_open_bucket_get(struct bch_fs *c,
} }
} }
enum bucket_alloc_ret int bch2_bucket_alloc_set(struct bch_fs *, struct open_buckets *,
bch2_bucket_alloc_set(struct bch_fs *, struct open_buckets *,
struct dev_stripe_state *, struct bch_devs_mask *, struct dev_stripe_state *, struct bch_devs_mask *,
unsigned, unsigned *, bool *, enum alloc_reserve, unsigned, unsigned *, bool *, enum alloc_reserve,
unsigned, struct closure *); unsigned, struct closure *);
......
...@@ -200,6 +200,7 @@ ...@@ -200,6 +200,7 @@
#include <linux/zstd.h> #include <linux/zstd.h>
#include "bcachefs_format.h" #include "bcachefs_format.h"
#include "errcode.h"
#include "fifo.h" #include "fifo.h"
#include "opts.h" #include "opts.h"
#include "util.h" #include "util.h"
......
...@@ -1272,8 +1272,7 @@ struct ec_stripe_head *__bch2_ec_stripe_head_get(struct bch_fs *c, ...@@ -1272,8 +1272,7 @@ struct ec_stripe_head *__bch2_ec_stripe_head_get(struct bch_fs *c,
return h; return h;
} }
static enum bucket_alloc_ret static int new_stripe_alloc_buckets(struct bch_fs *c, struct ec_stripe_head *h,
new_stripe_alloc_buckets(struct bch_fs *c, struct ec_stripe_head *h,
struct closure *cl) struct closure *cl)
{ {
struct bch_devs_mask devs = h->devs; struct bch_devs_mask devs = h->devs;
...@@ -1281,7 +1280,7 @@ new_stripe_alloc_buckets(struct bch_fs *c, struct ec_stripe_head *h, ...@@ -1281,7 +1280,7 @@ new_stripe_alloc_buckets(struct bch_fs *c, struct ec_stripe_head *h,
struct open_buckets buckets; struct open_buckets buckets;
unsigned i, j, nr_have_parity = 0, nr_have_data = 0; unsigned i, j, nr_have_parity = 0, nr_have_data = 0;
bool have_cache = true; 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++) { for (i = 0; i < h->s->new_stripe.key.v.nr_blocks; i++) {
if (test_bit(i, h->s->blocks_gotten)) { 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, ...@@ -1516,7 +1515,7 @@ struct ec_stripe_head *bch2_ec_stripe_head_get(struct bch_fs *c,
err: err:
bch2_ec_stripe_head_put(c, h); 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) void bch2_ec_stop_dev(struct bch_fs *c, struct bch_dev *ca)
......
/* 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 */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment