mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-08 14:23:19 +00:00
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: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
parent
dcfc593f7b
commit
fc6c01e2ea
@ -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 @@ open_bucket_add_buckets(struct bch_fs *c,
|
||||
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 @@ struct write_point *bch2_alloc_sectors_start(struct bch_fs *c,
|
||||
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 @@ struct write_point *bch2_alloc_sectors_start(struct bch_fs *c,
|
||||
|
||||
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();
|
||||
|
@ -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 *);
|
||||
|
@ -200,6 +200,7 @@
|
||||
#include <linux/zstd.h>
|
||||
|
||||
#include "bcachefs_format.h"
|
||||
#include "errcode.h"
|
||||
#include "fifo.h"
|
||||
#include "opts.h"
|
||||
#include "util.h"
|
||||
|
@ -1272,16 +1272,15 @@ struct ec_stripe_head *__bch2_ec_stripe_head_get(struct bch_fs *c,
|
||||
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)
|
||||
|
12
fs/bcachefs/errcode.h
Normal file
12
fs/bcachefs/errcode.h
Normal file
@ -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 */
|
Loading…
Reference in New Issue
Block a user