mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-24 17:23:25 -05:00
bcachefs: Add private error codes for ENOSPC
Continuing the saga of introducing private dedicated error codes for each error path, this patch converts ENOSPC to error codes that are subtypes of ENOSPC. We've recently had a test failure where we got -ENOSPC where we shouldn't have, and didn't have enough information to tell where it came from, so this patch will solve that problem. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
5c1ef830f6
commit
098ef98d5b
16 changed files with 55 additions and 36 deletions
|
@ -1246,7 +1246,9 @@ err:
|
||||||
|
|
||||||
if (bch2_err_matches(ret, BCH_ERR_open_buckets_empty) ||
|
if (bch2_err_matches(ret, BCH_ERR_open_buckets_empty) ||
|
||||||
bch2_err_matches(ret, BCH_ERR_freelist_empty))
|
bch2_err_matches(ret, BCH_ERR_freelist_empty))
|
||||||
return cl ? -EAGAIN : -ENOSPC;
|
return cl
|
||||||
|
? -EAGAIN
|
||||||
|
: -BCH_ERR_ENOSPC_bucket_alloc;
|
||||||
|
|
||||||
if (bch2_err_matches(ret, BCH_ERR_insufficient_devices))
|
if (bch2_err_matches(ret, BCH_ERR_insufficient_devices))
|
||||||
return -EROFS;
|
return -EROFS;
|
||||||
|
|
|
@ -1037,9 +1037,11 @@ int bch2_trans_commit_error(struct btree_trans *trans,
|
||||||
}
|
}
|
||||||
|
|
||||||
BUG_ON(bch2_err_matches(ret, BCH_ERR_transaction_restart) != !!trans->restarted);
|
BUG_ON(bch2_err_matches(ret, BCH_ERR_transaction_restart) != !!trans->restarted);
|
||||||
BUG_ON(ret == -ENOSPC &&
|
|
||||||
!(trans->flags & BTREE_INSERT_NOWAIT) &&
|
bch2_fs_inconsistent_on(bch2_err_matches(ret, ENOSPC) &&
|
||||||
(trans->flags & BTREE_INSERT_NOFAIL));
|
!(trans->flags & BTREE_INSERT_NOWAIT) &&
|
||||||
|
(trans->flags & BTREE_INSERT_NOFAIL), c,
|
||||||
|
"%s: incorrectly got %s\n", __func__, bch2_err_str(ret));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1991,7 +1991,7 @@ recalculate:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
} else {
|
} else {
|
||||||
atomic64_set(&c->sectors_available, sectors_available);
|
atomic64_set(&c->sectors_available, sectors_available);
|
||||||
ret = -ENOSPC;
|
ret = -BCH_ERR_ENOSPC_disk_reservation;
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&c->sectors_available_lock);
|
mutex_unlock(&c->sectors_available_lock);
|
||||||
|
|
|
@ -276,7 +276,7 @@ static int __bch2_disk_group_add(struct bch_sb_handle *sb, unsigned parent,
|
||||||
|
|
||||||
groups = bch2_sb_resize_disk_groups(sb, u64s);
|
groups = bch2_sb_resize_disk_groups(sb, u64s);
|
||||||
if (!groups)
|
if (!groups)
|
||||||
return -ENOSPC;
|
return -BCH_ERR_ENOSPC_disk_label_add;
|
||||||
|
|
||||||
nr_groups = disk_groups_nr(groups);
|
nr_groups = disk_groups_nr(groups);
|
||||||
}
|
}
|
||||||
|
|
|
@ -731,7 +731,7 @@ static int ec_stripe_bkey_insert(struct btree_trans *trans,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = -ENOSPC;
|
ret = -BCH_ERR_ENOSPC_stripe_create;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1388,7 +1388,7 @@ static int __bch2_ec_stripe_head_reuse(struct bch_fs *c,
|
||||||
idx = get_existing_stripe(c, h);
|
idx = get_existing_stripe(c, h);
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
bch_err(c, "failed to find an existing stripe");
|
bch_err(c, "failed to find an existing stripe");
|
||||||
return -ENOSPC;
|
return -BCH_ERR_ENOSPC_stripe_reuse;
|
||||||
}
|
}
|
||||||
|
|
||||||
h->s->have_existing_stripe = true;
|
h->s->have_existing_stripe = true;
|
||||||
|
|
|
@ -2,7 +2,21 @@
|
||||||
#ifndef _BCACHEFS_ERRCODE_H
|
#ifndef _BCACHEFS_ERRCODE_H
|
||||||
#define _BCACHEFS_ERRCODE_H
|
#define _BCACHEFS_ERRCODE_H
|
||||||
|
|
||||||
#define BCH_ERRCODES() \
|
#define BCH_ERRCODES() \
|
||||||
|
x(ENOSPC, ENOSPC_disk_reservation) \
|
||||||
|
x(ENOSPC, ENOSPC_bucket_alloc) \
|
||||||
|
x(ENOSPC, ENOSPC_disk_label_add) \
|
||||||
|
x(ENOSPC, ENOSPC_stripe_create) \
|
||||||
|
x(ENOSPC, ENOSPC_stripe_reuse) \
|
||||||
|
x(ENOSPC, ENOSPC_inode_create) \
|
||||||
|
x(ENOSPC, ENOSPC_str_hash_create) \
|
||||||
|
x(ENOSPC, ENOSPC_snapshot_create) \
|
||||||
|
x(ENOSPC, ENOSPC_subvolume_create) \
|
||||||
|
x(ENOSPC, ENOSPC_sb) \
|
||||||
|
x(ENOSPC, ENOSPC_sb_journal) \
|
||||||
|
x(ENOSPC, ENOSPC_sb_quota) \
|
||||||
|
x(ENOSPC, ENOSPC_sb_replicas) \
|
||||||
|
x(ENOSPC, ENOSPC_sb_members) \
|
||||||
x(0, open_buckets_empty) \
|
x(0, open_buckets_empty) \
|
||||||
x(0, freelist_empty) \
|
x(0, freelist_empty) \
|
||||||
x(BCH_ERR_freelist_empty, no_buckets_found) \
|
x(BCH_ERR_freelist_empty, no_buckets_found) \
|
||||||
|
|
|
@ -3031,7 +3031,7 @@ bkey_err:
|
||||||
bch2_trans_unlock(&trans); /* lock ordering, before taking pagecache locks: */
|
bch2_trans_unlock(&trans); /* lock ordering, before taking pagecache locks: */
|
||||||
mark_pagecache_reserved(inode, start_sector, iter.pos.offset);
|
mark_pagecache_reserved(inode, start_sector, iter.pos.offset);
|
||||||
|
|
||||||
if (ret == -ENOSPC && (mode & FALLOC_FL_ZERO_RANGE)) {
|
if (bch2_err_matches(ret, ENOSPC) && (mode & FALLOC_FL_ZERO_RANGE)) {
|
||||||
struct quota_res quota_res = { 0 };
|
struct quota_res quota_res = { 0 };
|
||||||
s64 i_sectors_delta = 0;
|
s64 i_sectors_delta = 0;
|
||||||
|
|
||||||
|
@ -3082,7 +3082,7 @@ static long bchfs_fallocate(struct bch_inode_info *inode, int mode,
|
||||||
* so that the VFS cache i_size is consistent with the btree i_size:
|
* so that the VFS cache i_size is consistent with the btree i_size:
|
||||||
*/
|
*/
|
||||||
if (ret &&
|
if (ret &&
|
||||||
!(ret == -ENOSPC && (mode & FALLOC_FL_ZERO_RANGE)))
|
!(bch2_err_matches(ret, ENOSPC) && (mode & FALLOC_FL_ZERO_RANGE)))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (mode & FALLOC_FL_KEEP_SIZE && end > inode->v.i_size)
|
if (mode & FALLOC_FL_KEEP_SIZE && end > inode->v.i_size)
|
||||||
|
|
|
@ -552,7 +552,7 @@ again:
|
||||||
goto found_slot;
|
goto found_slot;
|
||||||
|
|
||||||
if (!ret && start == min)
|
if (!ret && start == min)
|
||||||
ret = -ENOSPC;
|
ret = -BCH_ERR_ENOSPC_inode_create;
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
bch2_trans_iter_exit(trans, iter);
|
bch2_trans_iter_exit(trans, iter);
|
||||||
|
|
|
@ -808,14 +808,16 @@ static int __bch2_set_nr_journal_buckets(struct bch_dev *ca, unsigned nr,
|
||||||
if (new_fs) {
|
if (new_fs) {
|
||||||
bu[nr_got] = bch2_bucket_alloc_new_fs(ca);
|
bu[nr_got] = bch2_bucket_alloc_new_fs(ca);
|
||||||
if (bu[nr_got] < 0) {
|
if (bu[nr_got] < 0) {
|
||||||
ret = -ENOSPC;
|
ret = -BCH_ERR_ENOSPC_bucket_alloc;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ob[nr_got] = bch2_bucket_alloc(c, ca, RESERVE_none,
|
ob[nr_got] = bch2_bucket_alloc(c, ca, RESERVE_none,
|
||||||
false, cl);
|
false, cl);
|
||||||
if (IS_ERR(ob[nr_got])) {
|
if (IS_ERR(ob[nr_got])) {
|
||||||
ret = cl ? -EAGAIN : -ENOSPC;
|
ret = cl
|
||||||
|
? -EAGAIN
|
||||||
|
: -BCH_ERR_ENOSPC_bucket_alloc;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -942,10 +944,11 @@ int bch2_set_nr_journal_buckets(struct bch_fs *c, struct bch_dev *ca,
|
||||||
* reservation to ensure we'll actually be able to allocate:
|
* reservation to ensure we'll actually be able to allocate:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (bch2_disk_reservation_get(c, &disk_res,
|
ret = bch2_disk_reservation_get(c, &disk_res,
|
||||||
bucket_to_sector(ca, nr - ja->nr), 1, 0)) {
|
bucket_to_sector(ca, nr - ja->nr), 1, 0);
|
||||||
|
if (ret) {
|
||||||
mutex_unlock(&c->sb_lock);
|
mutex_unlock(&c->sb_lock);
|
||||||
return -ENOSPC;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = __bch2_set_nr_journal_buckets(ca, nr, false, &cl);
|
ret = __bch2_set_nr_journal_buckets(ca, nr, false, &cl);
|
||||||
|
|
|
@ -197,7 +197,7 @@ int bch2_journal_buckets_to_sb(struct bch_fs *c, struct bch_dev *ca)
|
||||||
j = bch2_sb_resize_journal_v2(&ca->disk_sb,
|
j = bch2_sb_resize_journal_v2(&ca->disk_sb,
|
||||||
(sizeof(*j) + sizeof(j->d[0]) * nr) / sizeof(u64));
|
(sizeof(*j) + sizeof(j->d[0]) * nr) / sizeof(u64));
|
||||||
if (!j)
|
if (!j)
|
||||||
return -ENOSPC;
|
return -BCH_ERR_ENOSPC_sb_journal;
|
||||||
|
|
||||||
bch2_sb_field_delete(&ca->disk_sb, BCH_SB_FIELD_journal);
|
bch2_sb_field_delete(&ca->disk_sb, BCH_SB_FIELD_journal);
|
||||||
|
|
||||||
|
|
|
@ -665,7 +665,7 @@ static int bch2_quota_set_info(struct super_block *sb, int type,
|
||||||
sb_quota = bch2_sb_resize_quota(&c->disk_sb,
|
sb_quota = bch2_sb_resize_quota(&c->disk_sb,
|
||||||
sizeof(*sb_quota) / sizeof(u64));
|
sizeof(*sb_quota) / sizeof(u64));
|
||||||
if (!sb_quota)
|
if (!sb_quota)
|
||||||
return -ENOSPC;
|
return -BCH_ERR_ENOSPC_sb_quota;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->i_fieldmask & QC_SPC_TIMER)
|
if (info->i_fieldmask & QC_SPC_TIMER)
|
||||||
|
|
|
@ -485,7 +485,7 @@ int bch2_replicas_gc_end(struct bch_fs *c, int ret)
|
||||||
bch2_fs_usage_read_one(c, &c->usage_base->replicas[i])) {
|
bch2_fs_usage_read_one(c, &c->usage_base->replicas[i])) {
|
||||||
n = cpu_replicas_add_entry(&c->replicas_gc, e);
|
n = cpu_replicas_add_entry(&c->replicas_gc, e);
|
||||||
if (!n.entries) {
|
if (!n.entries) {
|
||||||
ret = -ENOSPC;
|
ret = -ENOMEM;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,10 +494,9 @@ int bch2_replicas_gc_end(struct bch_fs *c, int ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bch2_cpu_replicas_to_sb_replicas(c, &c->replicas_gc)) {
|
ret = bch2_cpu_replicas_to_sb_replicas(c, &c->replicas_gc);
|
||||||
ret = -ENOSPC;
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
ret = replicas_table_update(c, &c->replicas_gc);
|
ret = replicas_table_update(c, &c->replicas_gc);
|
||||||
err:
|
err:
|
||||||
|
@ -600,10 +599,9 @@ retry:
|
||||||
|
|
||||||
bch2_cpu_replicas_sort(&new);
|
bch2_cpu_replicas_sort(&new);
|
||||||
|
|
||||||
if (bch2_cpu_replicas_to_sb_replicas(c, &new)) {
|
ret = bch2_cpu_replicas_to_sb_replicas(c, &new);
|
||||||
ret = -ENOSPC;
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
ret = replicas_table_update(c, &new);
|
ret = replicas_table_update(c, &new);
|
||||||
err:
|
err:
|
||||||
|
@ -758,7 +756,7 @@ static int bch2_cpu_replicas_to_sb_replicas_v0(struct bch_fs *c,
|
||||||
sb_r = bch2_sb_resize_replicas_v0(&c->disk_sb,
|
sb_r = bch2_sb_resize_replicas_v0(&c->disk_sb,
|
||||||
DIV_ROUND_UP(bytes, sizeof(u64)));
|
DIV_ROUND_UP(bytes, sizeof(u64)));
|
||||||
if (!sb_r)
|
if (!sb_r)
|
||||||
return -ENOSPC;
|
return -BCH_ERR_ENOSPC_sb_replicas;
|
||||||
|
|
||||||
bch2_sb_field_delete(&c->disk_sb, BCH_SB_FIELD_replicas);
|
bch2_sb_field_delete(&c->disk_sb, BCH_SB_FIELD_replicas);
|
||||||
sb_r = bch2_sb_get_replicas_v0(c->disk_sb.sb);
|
sb_r = bch2_sb_get_replicas_v0(c->disk_sb.sb);
|
||||||
|
@ -803,7 +801,7 @@ static int bch2_cpu_replicas_to_sb_replicas(struct bch_fs *c,
|
||||||
sb_r = bch2_sb_resize_replicas(&c->disk_sb,
|
sb_r = bch2_sb_resize_replicas(&c->disk_sb,
|
||||||
DIV_ROUND_UP(bytes, sizeof(u64)));
|
DIV_ROUND_UP(bytes, sizeof(u64)));
|
||||||
if (!sb_r)
|
if (!sb_r)
|
||||||
return -ENOSPC;
|
return -BCH_ERR_ENOSPC_sb_replicas;
|
||||||
|
|
||||||
bch2_sb_field_delete(&c->disk_sb, BCH_SB_FIELD_replicas_v0);
|
bch2_sb_field_delete(&c->disk_sb, BCH_SB_FIELD_replicas_v0);
|
||||||
sb_r = bch2_sb_get_replicas(c->disk_sb.sb);
|
sb_r = bch2_sb_get_replicas(c->disk_sb.sb);
|
||||||
|
|
|
@ -207,7 +207,7 @@ bch2_hash_hole(struct btree_trans *trans,
|
||||||
return 0;
|
return 0;
|
||||||
bch2_trans_iter_exit(trans, iter);
|
bch2_trans_iter_exit(trans, iter);
|
||||||
|
|
||||||
return ret ?: -ENOSPC;
|
return ret ?: -BCH_ERR_ENOSPC_str_hash_create;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __always_inline
|
static __always_inline
|
||||||
|
@ -277,7 +277,7 @@ int bch2_hash_set_snapshot(struct btree_trans *trans,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = -ENOSPC;
|
ret = -BCH_ERR_ENOSPC_str_hash_create;
|
||||||
out:
|
out:
|
||||||
bch2_trans_iter_exit(trans, &slot);
|
bch2_trans_iter_exit(trans, &slot);
|
||||||
bch2_trans_iter_exit(trans, &iter);
|
bch2_trans_iter_exit(trans, &iter);
|
||||||
|
|
|
@ -517,7 +517,7 @@ int bch2_snapshot_node_create(struct btree_trans *trans, u32 parent,
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (!k.k || !k.k->p.offset) {
|
if (!k.k || !k.k->p.offset) {
|
||||||
ret = -ENOSPC;
|
ret = -BCH_ERR_ENOSPC_snapshot_create;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1031,7 +1031,7 @@ int bch2_subvolume_create(struct btree_trans *trans, u64 inode,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = -ENOSPC;
|
ret = -BCH_ERR_ENOSPC_subvolume_create;
|
||||||
goto err;
|
goto err;
|
||||||
found_slot:
|
found_slot:
|
||||||
snapshot_subvols[0] = dst_iter.pos.offset;
|
snapshot_subvols[0] = dst_iter.pos.offset;
|
||||||
|
|
|
@ -132,7 +132,7 @@ int bch2_sb_realloc(struct bch_sb_handle *sb, unsigned u64s)
|
||||||
if (new_bytes > max_bytes) {
|
if (new_bytes > max_bytes) {
|
||||||
pr_err("%pg: superblock too big: want %zu but have %llu",
|
pr_err("%pg: superblock too big: want %zu but have %llu",
|
||||||
sb->bdev, new_bytes, max_bytes);
|
sb->bdev, new_bytes, max_bytes);
|
||||||
return -ENOSPC;
|
return -BCH_ERR_ENOSPC_sb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1584,7 +1584,7 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
|
||||||
le32_to_cpu(mi->field.u64s) +
|
le32_to_cpu(mi->field.u64s) +
|
||||||
sizeof(dev_mi) / sizeof(u64))) {
|
sizeof(dev_mi) / sizeof(u64))) {
|
||||||
bch_err(c, "device add error: new device superblock too small");
|
bch_err(c, "device add error: new device superblock too small");
|
||||||
ret = -ENOSPC;
|
ret = -BCH_ERR_ENOSPC_sb_members;
|
||||||
goto err_unlock;
|
goto err_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1597,7 +1597,7 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
|
||||||
goto have_slot;
|
goto have_slot;
|
||||||
no_slot:
|
no_slot:
|
||||||
bch_err(c, "device add error: already have maximum number of devices");
|
bch_err(c, "device add error: already have maximum number of devices");
|
||||||
ret = -ENOSPC;
|
ret = -BCH_ERR_ENOSPC_sb_members;
|
||||||
goto err_unlock;
|
goto err_unlock;
|
||||||
|
|
||||||
have_slot:
|
have_slot:
|
||||||
|
@ -1608,7 +1608,7 @@ have_slot:
|
||||||
mi = bch2_sb_resize_members(&c->disk_sb, u64s);
|
mi = bch2_sb_resize_members(&c->disk_sb, u64s);
|
||||||
if (!mi) {
|
if (!mi) {
|
||||||
bch_err(c, "device add error: no room in superblock for member info");
|
bch_err(c, "device add error: no room in superblock for member info");
|
||||||
ret = -ENOSPC;
|
ret = -BCH_ERR_ENOSPC_sb_members;
|
||||||
goto err_unlock;
|
goto err_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue