Commit 78c0b75c authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: More errcode cleanup

We shouldn't be overloading standard error codes now that we have
provisions for bcachefs-specific errorcodes: this patch converts super.c
and super-io.c to per error site errcodes, with a bit of cleanup.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 5f659376
...@@ -302,7 +302,7 @@ int bch2_alloc_v1_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -302,7 +302,7 @@ int bch2_alloc_v1_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_u64s(a.k) < bch_alloc_v1_val_u64s(a.v)) { if (bkey_val_u64s(a.k) < bch_alloc_v1_val_u64s(a.v)) {
prt_printf(err, "incorrect value size (%zu < %u)", prt_printf(err, "incorrect value size (%zu < %u)",
bkey_val_u64s(a.k), bch_alloc_v1_val_u64s(a.v)); bkey_val_u64s(a.k), bch_alloc_v1_val_u64s(a.v));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
...@@ -315,7 +315,7 @@ int bch2_alloc_v2_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -315,7 +315,7 @@ int bch2_alloc_v2_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bch2_alloc_unpack_v2(&u, k)) { if (bch2_alloc_unpack_v2(&u, k)) {
prt_printf(err, "unpack error"); prt_printf(err, "unpack error");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
...@@ -328,7 +328,7 @@ int bch2_alloc_v3_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -328,7 +328,7 @@ int bch2_alloc_v3_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bch2_alloc_unpack_v3(&u, k)) { if (bch2_alloc_unpack_v3(&u, k)) {
prt_printf(err, "unpack error"); prt_printf(err, "unpack error");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
...@@ -342,14 +342,14 @@ int bch2_alloc_v4_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -342,14 +342,14 @@ int bch2_alloc_v4_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_bytes(k.k) != sizeof(struct bch_alloc_v4)) { if (bkey_val_bytes(k.k) != sizeof(struct bch_alloc_v4)) {
prt_printf(err, "bad val size (%zu != %zu)", prt_printf(err, "bad val size (%zu != %zu)",
bkey_val_bytes(k.k), sizeof(struct bch_alloc_v4)); bkey_val_bytes(k.k), sizeof(struct bch_alloc_v4));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (rw == WRITE) { if (rw == WRITE) {
if (alloc_data_type(*a.v, a.v->data_type) != a.v->data_type) { if (alloc_data_type(*a.v, a.v->data_type) != a.v->data_type) {
prt_printf(err, "invalid data type (got %u should be %u)", prt_printf(err, "invalid data type (got %u should be %u)",
a.v->data_type, alloc_data_type(*a.v, a.v->data_type)); a.v->data_type, alloc_data_type(*a.v, a.v->data_type));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
switch (a.v->data_type) { switch (a.v->data_type) {
...@@ -360,7 +360,7 @@ int bch2_alloc_v4_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -360,7 +360,7 @@ int bch2_alloc_v4_invalid(const struct bch_fs *c, struct bkey_s_c k,
a.v->cached_sectors || a.v->cached_sectors ||
a.v->stripe) { a.v->stripe) {
prt_printf(err, "empty data type free but have data"); prt_printf(err, "empty data type free but have data");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
break; break;
case BCH_DATA_sb: case BCH_DATA_sb:
...@@ -371,7 +371,7 @@ int bch2_alloc_v4_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -371,7 +371,7 @@ int bch2_alloc_v4_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (!a.v->dirty_sectors) { if (!a.v->dirty_sectors) {
prt_printf(err, "data_type %s but dirty_sectors==0", prt_printf(err, "data_type %s but dirty_sectors==0",
bch2_data_types[a.v->data_type]); bch2_data_types[a.v->data_type]);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
break; break;
case BCH_DATA_cached: case BCH_DATA_cached:
...@@ -379,20 +379,20 @@ int bch2_alloc_v4_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -379,20 +379,20 @@ int bch2_alloc_v4_invalid(const struct bch_fs *c, struct bkey_s_c k,
a.v->dirty_sectors || a.v->dirty_sectors ||
a.v->stripe) { a.v->stripe) {
prt_printf(err, "data type inconsistency"); prt_printf(err, "data type inconsistency");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (!a.v->io_time[READ] && if (!a.v->io_time[READ] &&
test_bit(BCH_FS_CHECK_ALLOC_TO_LRU_REFS_DONE, &c->flags)) { test_bit(BCH_FS_CHECK_ALLOC_TO_LRU_REFS_DONE, &c->flags)) {
prt_printf(err, "cached bucket with read_time == 0"); prt_printf(err, "cached bucket with read_time == 0");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
break; break;
case BCH_DATA_stripe: case BCH_DATA_stripe:
if (!a.v->stripe) { if (!a.v->stripe) {
prt_printf(err, "data_type %s but stripe==0", prt_printf(err, "data_type %s but stripe==0",
bch2_data_types[a.v->data_type]); bch2_data_types[a.v->data_type]);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
break; break;
} }
......
...@@ -42,7 +42,7 @@ static int empty_val_key_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -42,7 +42,7 @@ static int empty_val_key_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_bytes(k.k)) { if (bkey_val_bytes(k.k)) {
prt_printf(err, "incorrect value size (%zu != 0)", prt_printf(err, "incorrect value size (%zu != 0)",
bkey_val_bytes(k.k)); bkey_val_bytes(k.k));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
...@@ -58,7 +58,7 @@ static int key_type_cookie_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -58,7 +58,7 @@ static int key_type_cookie_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_bytes(k.k) != sizeof(struct bch_cookie)) { if (bkey_val_bytes(k.k) != sizeof(struct bch_cookie)) {
prt_printf(err, "incorrect value size (%zu != %zu)", prt_printf(err, "incorrect value size (%zu != %zu)",
bkey_val_bytes(k.k), sizeof(struct bch_cookie)); bkey_val_bytes(k.k), sizeof(struct bch_cookie));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
...@@ -99,7 +99,7 @@ static int key_type_set_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -99,7 +99,7 @@ static int key_type_set_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_bytes(k.k)) { if (bkey_val_bytes(k.k)) {
prt_printf(err, "incorrect value size (%zu != %zu)", prt_printf(err, "incorrect value size (%zu != %zu)",
bkey_val_bytes(k.k), sizeof(struct bch_cookie)); bkey_val_bytes(k.k), sizeof(struct bch_cookie));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
...@@ -127,7 +127,7 @@ int bch2_bkey_val_invalid(struct bch_fs *c, struct bkey_s_c k, ...@@ -127,7 +127,7 @@ int bch2_bkey_val_invalid(struct bch_fs *c, struct bkey_s_c k,
{ {
if (k.k->type >= KEY_TYPE_MAX) { if (k.k->type >= KEY_TYPE_MAX) {
prt_printf(err, "invalid type (%u >= %u)", k.k->type, KEY_TYPE_MAX); prt_printf(err, "invalid type (%u >= %u)", k.k->type, KEY_TYPE_MAX);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return bch2_bkey_ops[k.k->type].key_invalid(c, k, rw, err); return bch2_bkey_ops[k.k->type].key_invalid(c, k, rw, err);
...@@ -203,30 +203,30 @@ int __bch2_bkey_invalid(struct bch_fs *c, struct bkey_s_c k, ...@@ -203,30 +203,30 @@ int __bch2_bkey_invalid(struct bch_fs *c, struct bkey_s_c k,
{ {
if (k.k->u64s < BKEY_U64s) { if (k.k->u64s < BKEY_U64s) {
prt_printf(err, "u64s too small (%u < %zu)", k.k->u64s, BKEY_U64s); prt_printf(err, "u64s too small (%u < %zu)", k.k->u64s, BKEY_U64s);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (!(bch2_key_types_allowed[type] & (1U << k.k->type))) { if (!(bch2_key_types_allowed[type] & (1U << k.k->type))) {
prt_printf(err, "invalid key type for btree %s (%s)", prt_printf(err, "invalid key type for btree %s (%s)",
bch2_btree_ids[type], bch2_bkey_types[k.k->type]); bch2_btree_ids[type], bch2_bkey_types[k.k->type]);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (btree_node_type_is_extents(type) && !bkey_whiteout(k.k)) { if (btree_node_type_is_extents(type) && !bkey_whiteout(k.k)) {
if (k.k->size == 0) { if (k.k->size == 0) {
prt_printf(err, "size == 0"); prt_printf(err, "size == 0");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (k.k->size > k.k->p.offset) { if (k.k->size > k.k->p.offset) {
prt_printf(err, "size greater than offset (%u > %llu)", prt_printf(err, "size greater than offset (%u > %llu)",
k.k->size, k.k->p.offset); k.k->size, k.k->p.offset);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
} else { } else {
if (k.k->size) { if (k.k->size) {
prt_printf(err, "size != 0"); prt_printf(err, "size != 0");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
} }
...@@ -234,20 +234,20 @@ int __bch2_bkey_invalid(struct bch_fs *c, struct bkey_s_c k, ...@@ -234,20 +234,20 @@ int __bch2_bkey_invalid(struct bch_fs *c, struct bkey_s_c k,
!btree_type_has_snapshots(type) && !btree_type_has_snapshots(type) &&
k.k->p.snapshot) { k.k->p.snapshot) {
prt_printf(err, "nonzero snapshot"); prt_printf(err, "nonzero snapshot");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (type != BKEY_TYPE_btree && if (type != BKEY_TYPE_btree &&
btree_type_has_snapshots(type) && btree_type_has_snapshots(type) &&
!k.k->p.snapshot) { !k.k->p.snapshot) {
prt_printf(err, "snapshot == 0"); prt_printf(err, "snapshot == 0");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (type != BKEY_TYPE_btree && if (type != BKEY_TYPE_btree &&
bkey_eq(k.k->p, POS_MAX)) { bkey_eq(k.k->p, POS_MAX)) {
prt_printf(err, "key at POS_MAX"); prt_printf(err, "key at POS_MAX");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
...@@ -266,12 +266,12 @@ int bch2_bkey_in_btree_node(struct btree *b, struct bkey_s_c k, ...@@ -266,12 +266,12 @@ int bch2_bkey_in_btree_node(struct btree *b, struct bkey_s_c k,
{ {
if (bpos_lt(k.k->p, b->data->min_key)) { if (bpos_lt(k.k->p, b->data->min_key)) {
prt_printf(err, "key before start of btree node"); prt_printf(err, "key before start of btree node");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (bpos_gt(k.k->p, b->data->max_key)) { if (bpos_gt(k.k->p, b->data->max_key)) {
prt_printf(err, "key past end of btree node"); prt_printf(err, "key past end of btree node");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
......
...@@ -92,46 +92,46 @@ int bch2_dirent_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -92,46 +92,46 @@ int bch2_dirent_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_bytes(k.k) < sizeof(struct bch_dirent)) { if (bkey_val_bytes(k.k) < sizeof(struct bch_dirent)) {
prt_printf(err, "incorrect value size (%zu < %zu)", prt_printf(err, "incorrect value size (%zu < %zu)",
bkey_val_bytes(k.k), sizeof(*d.v)); bkey_val_bytes(k.k), sizeof(*d.v));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
len = bch2_dirent_name_bytes(d); len = bch2_dirent_name_bytes(d);
if (!len) { if (!len) {
prt_printf(err, "empty name"); prt_printf(err, "empty name");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (bkey_val_u64s(k.k) > dirent_val_u64s(len)) { if (bkey_val_u64s(k.k) > dirent_val_u64s(len)) {
prt_printf(err, "value too big (%zu > %u)", prt_printf(err, "value too big (%zu > %u)",
bkey_val_u64s(k.k), dirent_val_u64s(len)); bkey_val_u64s(k.k), dirent_val_u64s(len));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (len > BCH_NAME_MAX) { if (len > BCH_NAME_MAX) {
prt_printf(err, "dirent name too big (%u > %u)", prt_printf(err, "dirent name too big (%u > %u)",
len, BCH_NAME_MAX); len, BCH_NAME_MAX);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (len == 1 && !memcmp(d.v->d_name, ".", 1)) { if (len == 1 && !memcmp(d.v->d_name, ".", 1)) {
prt_printf(err, "invalid name"); prt_printf(err, "invalid name");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (len == 2 && !memcmp(d.v->d_name, "..", 2)) { if (len == 2 && !memcmp(d.v->d_name, "..", 2)) {
prt_printf(err, "invalid name"); prt_printf(err, "invalid name");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (memchr(d.v->d_name, '/', len)) { if (memchr(d.v->d_name, '/', len)) {
prt_printf(err, "invalid name"); prt_printf(err, "invalid name");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (d.v->d_type != DT_SUBVOL && if (d.v->d_type != DT_SUBVOL &&
le64_to_cpu(d.v->d_inum) == d.k->p.inode) { le64_to_cpu(d.v->d_inum) == d.k->p.inode) {
prt_printf(err, "dirent points to own directory"); prt_printf(err, "dirent points to own directory");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
......
...@@ -27,7 +27,7 @@ static int bch2_sb_disk_groups_validate(struct bch_sb *sb, ...@@ -27,7 +27,7 @@ static int bch2_sb_disk_groups_validate(struct bch_sb *sb,
struct bch_sb_field_members *mi = bch2_sb_get_members(sb); struct bch_sb_field_members *mi = bch2_sb_get_members(sb);
unsigned nr_groups = disk_groups_nr(groups); unsigned nr_groups = disk_groups_nr(groups);
unsigned i, len; unsigned i, len;
int ret = -EINVAL; int ret = 0;
for (i = 0; i < sb->nr_devices; i++) { for (i = 0; i < sb->nr_devices; i++) {
struct bch_member *m = mi->members + i; struct bch_member *m = mi->members + i;
...@@ -41,12 +41,12 @@ static int bch2_sb_disk_groups_validate(struct bch_sb *sb, ...@@ -41,12 +41,12 @@ static int bch2_sb_disk_groups_validate(struct bch_sb *sb,
if (g >= nr_groups) { if (g >= nr_groups) {
prt_printf(err, "disk %u has invalid label %u (have %u)", prt_printf(err, "disk %u has invalid label %u (have %u)",
i, g, nr_groups); i, g, nr_groups);
return -EINVAL; return -BCH_ERR_invalid_sb_disk_groups;
} }
if (BCH_GROUP_DELETED(&groups->entries[g])) { if (BCH_GROUP_DELETED(&groups->entries[g])) {
prt_printf(err, "disk %u has deleted label %u", i, g); prt_printf(err, "disk %u has deleted label %u", i, g);
return -EINVAL; return -BCH_ERR_invalid_sb_disk_groups;
} }
} }
...@@ -62,7 +62,7 @@ static int bch2_sb_disk_groups_validate(struct bch_sb *sb, ...@@ -62,7 +62,7 @@ static int bch2_sb_disk_groups_validate(struct bch_sb *sb,
len = strnlen(g->label, sizeof(g->label)); len = strnlen(g->label, sizeof(g->label));
if (!len) { if (!len) {
prt_printf(err, "label %u empty", i); prt_printf(err, "label %u empty", i);
return -EINVAL; return -BCH_ERR_invalid_sb_disk_groups;
} }
} }
...@@ -79,13 +79,12 @@ static int bch2_sb_disk_groups_validate(struct bch_sb *sb, ...@@ -79,13 +79,12 @@ static int bch2_sb_disk_groups_validate(struct bch_sb *sb,
prt_printf(err, "duplicate label %llu.%.*s", prt_printf(err, "duplicate label %llu.%.*s",
BCH_GROUP_PARENT(g), BCH_GROUP_PARENT(g),
(int) sizeof(g->label), g->label); (int) sizeof(g->label), g->label);
ret = -BCH_ERR_invalid_sb_disk_groups;
goto err; goto err;
} }
ret = 0;
err: err:
kfree(sorted); kfree(sorted);
return 0; return ret;
} }
static void bch2_sb_disk_groups_to_text(struct printbuf *out, static void bch2_sb_disk_groups_to_text(struct printbuf *out,
......
...@@ -109,24 +109,24 @@ int bch2_stripe_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -109,24 +109,24 @@ int bch2_stripe_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_eq(k.k->p, POS_MIN)) { if (bkey_eq(k.k->p, POS_MIN)) {
prt_printf(err, "stripe at POS_MIN"); prt_printf(err, "stripe at POS_MIN");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (k.k->p.inode) { if (k.k->p.inode) {
prt_printf(err, "nonzero inode field"); prt_printf(err, "nonzero inode field");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (bkey_val_bytes(k.k) < sizeof(*s)) { if (bkey_val_bytes(k.k) < sizeof(*s)) {
prt_printf(err, "incorrect value size (%zu < %zu)", prt_printf(err, "incorrect value size (%zu < %zu)",
bkey_val_bytes(k.k), sizeof(*s)); bkey_val_bytes(k.k), sizeof(*s));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (bkey_val_u64s(k.k) < stripe_val_u64s(s)) { if (bkey_val_u64s(k.k) < stripe_val_u64s(s)) {
prt_printf(err, "incorrect value size (%zu < %u)", prt_printf(err, "incorrect value size (%zu < %u)",
bkey_val_u64s(k.k), stripe_val_u64s(s)); bkey_val_u64s(k.k), stripe_val_u64s(s));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return bch2_bkey_ptrs_invalid(c, k, rw, err); return bch2_bkey_ptrs_invalid(c, k, rw, err);
......
...@@ -67,7 +67,45 @@ ...@@ -67,7 +67,45 @@
x(BCH_ERR_fsck, fsck_repair_unimplemented) \ x(BCH_ERR_fsck, fsck_repair_unimplemented) \
x(BCH_ERR_fsck, fsck_repair_impossible) \ x(BCH_ERR_fsck, fsck_repair_impossible) \
x(0, need_snapshot_cleanup) \ x(0, need_snapshot_cleanup) \
x(0, need_topology_repair) x(0, need_topology_repair) \
x(EINVAL, device_state_not_allowed) \
x(EINVAL, member_info_missing) \
x(EINVAL, mismatched_block_size) \
x(EINVAL, block_size_too_small) \
x(EINVAL, bucket_size_too_small) \
x(EINVAL, device_size_too_small) \
x(EINVAL, device_not_a_member_of_filesystem) \
x(EINVAL, device_has_been_removed) \
x(EINVAL, device_already_online) \
x(EINVAL, insufficient_devices_to_start) \
x(EINVAL, invalid) \
x(BCH_ERR_invalid, invalid_sb) \
x(BCH_ERR_invalid_sb, invalid_sb_magic) \
x(BCH_ERR_invalid_sb, invalid_sb_version) \
x(BCH_ERR_invalid_sb, invalid_sb_features) \
x(BCH_ERR_invalid_sb, invalid_sb_too_big) \
x(BCH_ERR_invalid_sb, invalid_sb_csum_type) \
x(BCH_ERR_invalid_sb, invalid_sb_csum) \
x(BCH_ERR_invalid_sb, invalid_sb_block_size) \
x(BCH_ERR_invalid_sb, invalid_sb_uuid) \
x(BCH_ERR_invalid_sb, invalid_sb_too_many_members) \
x(BCH_ERR_invalid_sb, invalid_sb_dev_idx) \
x(BCH_ERR_invalid_sb, invalid_sb_time_precision) \
x(BCH_ERR_invalid_sb, invalid_sb_field_size) \
x(BCH_ERR_invalid_sb, invalid_sb_layout) \
x(BCH_ERR_invalid_sb_layout, invalid_sb_layout_type) \
x(BCH_ERR_invalid_sb_layout, invalid_sb_layout_nr_superblocks) \
x(BCH_ERR_invalid_sb_layout, invalid_sb_layout_superblocks_overlap) \
x(BCH_ERR_invalid_sb, invalid_sb_members_missing) \
x(BCH_ERR_invalid_sb, invalid_sb_members) \
x(BCH_ERR_invalid_sb, invalid_sb_disk_groups) \
x(BCH_ERR_invalid_sb, invalid_sb_replicas) \
x(BCH_ERR_invalid_sb, invalid_sb_journal) \
x(BCH_ERR_invalid_sb, invalid_sb_journal_seq_blacklist) \
x(BCH_ERR_invalid_sb, invalid_sb_crypt) \
x(BCH_ERR_invalid_sb, invalid_sb_clean) \
x(BCH_ERR_invalid_sb, invalid_sb_quota) \
x(BCH_ERR_invalid, invalid_bkey) \
enum bch_errcode { enum bch_errcode {
BCH_ERR_START = 2048, BCH_ERR_START = 2048,
......
...@@ -163,7 +163,7 @@ int bch2_btree_ptr_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -163,7 +163,7 @@ int bch2_btree_ptr_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_u64s(k.k) > BCH_REPLICAS_MAX) { if (bkey_val_u64s(k.k) > BCH_REPLICAS_MAX) {
prt_printf(err, "value too big (%zu > %u)", prt_printf(err, "value too big (%zu > %u)",
bkey_val_u64s(k.k), BCH_REPLICAS_MAX); bkey_val_u64s(k.k), BCH_REPLICAS_MAX);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return bch2_bkey_ptrs_invalid(c, k, rw, err); return bch2_bkey_ptrs_invalid(c, k, rw, err);
...@@ -183,20 +183,20 @@ int bch2_btree_ptr_v2_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -183,20 +183,20 @@ int bch2_btree_ptr_v2_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_bytes(k.k) <= sizeof(*bp.v)) { if (bkey_val_bytes(k.k) <= sizeof(*bp.v)) {
prt_printf(err, "value too small (%zu <= %zu)", prt_printf(err, "value too small (%zu <= %zu)",
bkey_val_bytes(k.k), sizeof(*bp.v)); bkey_val_bytes(k.k), sizeof(*bp.v));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (bkey_val_u64s(k.k) > BKEY_BTREE_PTR_VAL_U64s_MAX) { if (bkey_val_u64s(k.k) > BKEY_BTREE_PTR_VAL_U64s_MAX) {
prt_printf(err, "value too big (%zu > %zu)", prt_printf(err, "value too big (%zu > %zu)",
bkey_val_u64s(k.k), BKEY_BTREE_PTR_VAL_U64s_MAX); bkey_val_u64s(k.k), BKEY_BTREE_PTR_VAL_U64s_MAX);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (c->sb.version < bcachefs_metadata_version_snapshot && if (c->sb.version < bcachefs_metadata_version_snapshot &&
bp.v->min_key.snapshot) { bp.v->min_key.snapshot) {
prt_printf(err, "invalid min_key.snapshot (%u != 0)", prt_printf(err, "invalid min_key.snapshot (%u != 0)",
bp.v->min_key.snapshot); bp.v->min_key.snapshot);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return bch2_bkey_ptrs_invalid(c, k, rw, err); return bch2_bkey_ptrs_invalid(c, k, rw, err);
...@@ -387,13 +387,13 @@ int bch2_reservation_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -387,13 +387,13 @@ int bch2_reservation_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_bytes(k.k) != sizeof(struct bch_reservation)) { if (bkey_val_bytes(k.k) != sizeof(struct bch_reservation)) {
prt_printf(err, "incorrect value size (%zu != %zu)", prt_printf(err, "incorrect value size (%zu != %zu)",
bkey_val_bytes(k.k), sizeof(*r.v)); bkey_val_bytes(k.k), sizeof(*r.v));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (!r.v->nr_replicas || r.v->nr_replicas > BCH_REPLICAS_MAX) { if (!r.v->nr_replicas || r.v->nr_replicas > BCH_REPLICAS_MAX) {
prt_printf(err, "invalid nr_replicas (%u)", prt_printf(err, "invalid nr_replicas (%u)",
r.v->nr_replicas); r.v->nr_replicas);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
...@@ -1054,14 +1054,14 @@ static int extent_ptr_invalid(const struct bch_fs *c, ...@@ -1054,14 +1054,14 @@ static int extent_ptr_invalid(const struct bch_fs *c,
if (!bch2_dev_exists2(c, ptr->dev)) { if (!bch2_dev_exists2(c, ptr->dev)) {
prt_printf(err, "pointer to invalid device (%u)", ptr->dev); prt_printf(err, "pointer to invalid device (%u)", ptr->dev);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
ca = bch_dev_bkey_exists(c, ptr->dev); ca = bch_dev_bkey_exists(c, ptr->dev);
bkey_for_each_ptr(ptrs, ptr2) bkey_for_each_ptr(ptrs, ptr2)
if (ptr != ptr2 && ptr->dev == ptr2->dev) { if (ptr != ptr2 && ptr->dev == ptr2->dev) {
prt_printf(err, "multiple pointers to same device (%u)", ptr->dev); prt_printf(err, "multiple pointers to same device (%u)", ptr->dev);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
bucket = sector_to_bucket_and_offset(ca, ptr->offset, &bucket_offset); bucket = sector_to_bucket_and_offset(ca, ptr->offset, &bucket_offset);
...@@ -1069,19 +1069,19 @@ static int extent_ptr_invalid(const struct bch_fs *c, ...@@ -1069,19 +1069,19 @@ static int extent_ptr_invalid(const struct bch_fs *c,
if (bucket >= ca->mi.nbuckets) { if (bucket >= ca->mi.nbuckets) {
prt_printf(err, "pointer past last bucket (%llu > %llu)", prt_printf(err, "pointer past last bucket (%llu > %llu)",
bucket, ca->mi.nbuckets); bucket, ca->mi.nbuckets);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (ptr->offset < bucket_to_sector(ca, ca->mi.first_bucket)) { if (ptr->offset < bucket_to_sector(ca, ca->mi.first_bucket)) {
prt_printf(err, "pointer before first bucket (%llu < %u)", prt_printf(err, "pointer before first bucket (%llu < %u)",
bucket, ca->mi.first_bucket); bucket, ca->mi.first_bucket);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (bucket_offset + size_ondisk > ca->mi.bucket_size) { if (bucket_offset + size_ondisk > ca->mi.bucket_size) {
prt_printf(err, "pointer spans multiple buckets (%u + %u > %u)", prt_printf(err, "pointer spans multiple buckets (%u + %u > %u)",
bucket_offset, size_ondisk, ca->mi.bucket_size); bucket_offset, size_ondisk, ca->mi.bucket_size);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
...@@ -1105,13 +1105,13 @@ int bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -1105,13 +1105,13 @@ int bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (__extent_entry_type(entry) >= BCH_EXTENT_ENTRY_MAX) { if (__extent_entry_type(entry) >= BCH_EXTENT_ENTRY_MAX) {
prt_printf(err, "invalid extent entry type (got %u, max %u)", prt_printf(err, "invalid extent entry type (got %u, max %u)",
__extent_entry_type(entry), BCH_EXTENT_ENTRY_MAX); __extent_entry_type(entry), BCH_EXTENT_ENTRY_MAX);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (bkey_is_btree_ptr(k.k) && if (bkey_is_btree_ptr(k.k) &&
!extent_entry_is_ptr(entry)) { !extent_entry_is_ptr(entry)) {
prt_printf(err, "has non ptr field"); prt_printf(err, "has non ptr field");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
switch (extent_entry_type(entry)) { switch (extent_entry_type(entry)) {
...@@ -1130,19 +1130,19 @@ int bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -1130,19 +1130,19 @@ int bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (crc.offset + crc.live_size > if (crc.offset + crc.live_size >
crc.uncompressed_size) { crc.uncompressed_size) {
prt_printf(err, "checksum offset + key size > uncompressed size"); prt_printf(err, "checksum offset + key size > uncompressed size");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
size_ondisk = crc.compressed_size; size_ondisk = crc.compressed_size;
if (!bch2_checksum_type_valid(c, crc.csum_type)) { if (!bch2_checksum_type_valid(c, crc.csum_type)) {
prt_printf(err, "invalid checksum type"); prt_printf(err, "invalid checksum type");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (crc.compression_type >= BCH_COMPRESSION_TYPE_NR) { if (crc.compression_type >= BCH_COMPRESSION_TYPE_NR) {
prt_printf(err, "invalid compression type"); prt_printf(err, "invalid compression type");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (bch2_csum_type_is_encryption(crc.csum_type)) { if (bch2_csum_type_is_encryption(crc.csum_type)) {
...@@ -1150,7 +1150,7 @@ int bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -1150,7 +1150,7 @@ int bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k,
nonce = crc.offset + crc.nonce; nonce = crc.offset + crc.nonce;
else if (nonce != crc.offset + crc.nonce) { else if (nonce != crc.offset + crc.nonce) {
prt_printf(err, "incorrect nonce"); prt_printf(err, "incorrect nonce");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
} }
break; break;
...@@ -1161,7 +1161,7 @@ int bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -1161,7 +1161,7 @@ int bch2_bkey_ptrs_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (nr_ptrs >= BCH_BKEY_PTRS_MAX) { if (nr_ptrs >= BCH_BKEY_PTRS_MAX) {
prt_str(err, "too many ptrs"); prt_str(err, "too many ptrs");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
......
...@@ -1767,8 +1767,11 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type, ...@@ -1767,8 +1767,11 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
kfree(devs[0]); kfree(devs[0]);
kfree(devs); kfree(devs);
if (IS_ERR(sb)) if (IS_ERR(sb)) {
return ERR_CAST(sb); ret = PTR_ERR(sb);
ret = bch2_err_class(ret);
return ERR_PTR(ret);
}
c = sb->s_fs_info; c = sb->s_fs_info;
......
...@@ -306,40 +306,40 @@ static int __bch2_inode_invalid(struct bkey_s_c k, struct printbuf *err) ...@@ -306,40 +306,40 @@ static int __bch2_inode_invalid(struct bkey_s_c k, struct printbuf *err)
if (k.k->p.inode) { if (k.k->p.inode) {
prt_printf(err, "nonzero k.p.inode"); prt_printf(err, "nonzero k.p.inode");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (k.k->p.offset < BLOCKDEV_INODE_MAX) { if (k.k->p.offset < BLOCKDEV_INODE_MAX) {
prt_printf(err, "fs inode in blockdev range"); prt_printf(err, "fs inode in blockdev range");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (bch2_inode_unpack(k, &unpacked)) { if (bch2_inode_unpack(k, &unpacked)) {
prt_printf(err, "invalid variable length fields"); prt_printf(err, "invalid variable length fields");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (unpacked.bi_data_checksum >= BCH_CSUM_OPT_NR + 1) { if (unpacked.bi_data_checksum >= BCH_CSUM_OPT_NR + 1) {
prt_printf(err, "invalid data checksum type (%u >= %u", prt_printf(err, "invalid data checksum type (%u >= %u",
unpacked.bi_data_checksum, BCH_CSUM_OPT_NR + 1); unpacked.bi_data_checksum, BCH_CSUM_OPT_NR + 1);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (unpacked.bi_compression >= BCH_COMPRESSION_OPT_NR + 1) { if (unpacked.bi_compression >= BCH_COMPRESSION_OPT_NR + 1) {
prt_printf(err, "invalid data checksum type (%u >= %u)", prt_printf(err, "invalid data checksum type (%u >= %u)",
unpacked.bi_compression, BCH_COMPRESSION_OPT_NR + 1); unpacked.bi_compression, BCH_COMPRESSION_OPT_NR + 1);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if ((unpacked.bi_flags & BCH_INODE_UNLINKED) && if ((unpacked.bi_flags & BCH_INODE_UNLINKED) &&
unpacked.bi_nlink != 0) { unpacked.bi_nlink != 0) {
prt_printf(err, "flagged as unlinked but bi_nlink != 0"); prt_printf(err, "flagged as unlinked but bi_nlink != 0");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (unpacked.bi_subvol && !S_ISDIR(unpacked.bi_mode)) { if (unpacked.bi_subvol && !S_ISDIR(unpacked.bi_mode)) {
prt_printf(err, "subvolume root but not a directory"); prt_printf(err, "subvolume root but not a directory");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
...@@ -353,13 +353,13 @@ int bch2_inode_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -353,13 +353,13 @@ int bch2_inode_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_bytes(k.k) < sizeof(*inode.v)) { if (bkey_val_bytes(k.k) < sizeof(*inode.v)) {
prt_printf(err, "incorrect value size (%zu < %zu)", prt_printf(err, "incorrect value size (%zu < %zu)",
bkey_val_bytes(k.k), sizeof(*inode.v)); bkey_val_bytes(k.k), sizeof(*inode.v));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (INODE_STR_HASH(inode.v) >= BCH_STR_HASH_NR) { if (INODE_STR_HASH(inode.v) >= BCH_STR_HASH_NR) {
prt_printf(err, "invalid str hash type (%llu >= %u)", prt_printf(err, "invalid str hash type (%llu >= %u)",
INODE_STR_HASH(inode.v), BCH_STR_HASH_NR); INODE_STR_HASH(inode.v), BCH_STR_HASH_NR);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return __bch2_inode_invalid(k, err); return __bch2_inode_invalid(k, err);
...@@ -373,13 +373,13 @@ int bch2_inode_v2_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -373,13 +373,13 @@ int bch2_inode_v2_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_bytes(k.k) < sizeof(*inode.v)) { if (bkey_val_bytes(k.k) < sizeof(*inode.v)) {
prt_printf(err, "incorrect value size (%zu < %zu)", prt_printf(err, "incorrect value size (%zu < %zu)",
bkey_val_bytes(k.k), sizeof(*inode.v)); bkey_val_bytes(k.k), sizeof(*inode.v));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (INODEv2_STR_HASH(inode.v) >= BCH_STR_HASH_NR) { if (INODEv2_STR_HASH(inode.v) >= BCH_STR_HASH_NR) {
prt_printf(err, "invalid str hash type (%llu >= %u)", prt_printf(err, "invalid str hash type (%llu >= %u)",
INODEv2_STR_HASH(inode.v), BCH_STR_HASH_NR); INODEv2_STR_HASH(inode.v), BCH_STR_HASH_NR);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return __bch2_inode_invalid(k, err); return __bch2_inode_invalid(k, err);
...@@ -421,13 +421,13 @@ int bch2_inode_generation_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -421,13 +421,13 @@ int bch2_inode_generation_invalid(const struct bch_fs *c, struct bkey_s_c k,
{ {
if (k.k->p.inode) { if (k.k->p.inode) {
prt_printf(err, "nonzero k.p.inode"); prt_printf(err, "nonzero k.p.inode");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (bkey_val_bytes(k.k) != sizeof(struct bch_inode_generation)) { if (bkey_val_bytes(k.k) != sizeof(struct bch_inode_generation)) {
prt_printf(err, "incorrect value size (%zu != %zu)", prt_printf(err, "incorrect value size (%zu != %zu)",
bkey_val_bytes(k.k), sizeof(struct bch_inode_generation)); bkey_val_bytes(k.k), sizeof(struct bch_inode_generation));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
......
...@@ -22,7 +22,7 @@ static int bch2_sb_journal_validate(struct bch_sb *sb, ...@@ -22,7 +22,7 @@ static int bch2_sb_journal_validate(struct bch_sb *sb,
{ {
struct bch_sb_field_journal *journal = field_to_type(f, journal); struct bch_sb_field_journal *journal = field_to_type(f, journal);
struct bch_member *m = bch2_sb_get_members(sb)->members + sb->dev_idx; struct bch_member *m = bch2_sb_get_members(sb)->members + sb->dev_idx;
int ret = -EINVAL; int ret = -BCH_ERR_invalid_sb_journal;
unsigned nr; unsigned nr;
unsigned i; unsigned i;
u64 *b; u64 *b;
...@@ -105,7 +105,7 @@ static int bch2_sb_journal_v2_validate(struct bch_sb *sb, ...@@ -105,7 +105,7 @@ static int bch2_sb_journal_v2_validate(struct bch_sb *sb,
{ {
struct bch_sb_field_journal_v2 *journal = field_to_type(f, journal_v2); struct bch_sb_field_journal_v2 *journal = field_to_type(f, journal_v2);
struct bch_member *m = bch2_sb_get_members(sb)->members + sb->dev_idx; struct bch_member *m = bch2_sb_get_members(sb)->members + sb->dev_idx;
int ret = -EINVAL; int ret = -BCH_ERR_invalid_sb_journal;
unsigned nr; unsigned nr;
unsigned i; unsigned i;
struct u64_range *b; struct u64_range *b;
......
...@@ -203,7 +203,7 @@ static int bch2_sb_journal_seq_blacklist_validate(struct bch_sb *sb, ...@@ -203,7 +203,7 @@ static int bch2_sb_journal_seq_blacklist_validate(struct bch_sb *sb,
le64_to_cpu(e->end)) { le64_to_cpu(e->end)) {
prt_printf(err, "entry %u start >= end (%llu >= %llu)", prt_printf(err, "entry %u start >= end (%llu >= %llu)",
i, le64_to_cpu(e->start), le64_to_cpu(e->end)); i, le64_to_cpu(e->start), le64_to_cpu(e->end));
return -EINVAL; return -BCH_ERR_invalid_sb_journal_seq_blacklist;
} }
if (i + 1 < nr && if (i + 1 < nr &&
...@@ -211,7 +211,7 @@ static int bch2_sb_journal_seq_blacklist_validate(struct bch_sb *sb, ...@@ -211,7 +211,7 @@ static int bch2_sb_journal_seq_blacklist_validate(struct bch_sb *sb,
le64_to_cpu(e[1].start)) { le64_to_cpu(e[1].start)) {
prt_printf(err, "entry %u out of order with next entry (%llu > %llu)", prt_printf(err, "entry %u out of order with next entry (%llu > %llu)",
i + 1, le64_to_cpu(e[0].end), le64_to_cpu(e[1].start)); i + 1, le64_to_cpu(e[0].end), le64_to_cpu(e[1].start));
return -EINVAL; return -BCH_ERR_invalid_sb_journal_seq_blacklist;
} }
} }
......
...@@ -16,7 +16,7 @@ int bch2_lru_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -16,7 +16,7 @@ int bch2_lru_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_bytes(k.k) < sizeof(*lru)) { if (bkey_val_bytes(k.k) < sizeof(*lru)) {
prt_printf(err, "incorrect value size (%zu < %zu)", prt_printf(err, "incorrect value size (%zu < %zu)",
bkey_val_bytes(k.k), sizeof(*lru)); bkey_val_bytes(k.k), sizeof(*lru));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
......
...@@ -26,7 +26,7 @@ static int bch2_sb_quota_validate(struct bch_sb *sb, struct bch_sb_field *f, ...@@ -26,7 +26,7 @@ static int bch2_sb_quota_validate(struct bch_sb *sb, struct bch_sb_field *f,
if (vstruct_bytes(&q->field) < sizeof(*q)) { if (vstruct_bytes(&q->field) < sizeof(*q)) {
prt_printf(err, "wrong size (got %zu should be %zu)", prt_printf(err, "wrong size (got %zu should be %zu)",
vstruct_bytes(&q->field), sizeof(*q)); vstruct_bytes(&q->field), sizeof(*q));
return -EINVAL; return -BCH_ERR_invalid_sb_quota;
} }
return 0; return 0;
...@@ -64,13 +64,13 @@ int bch2_quota_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -64,13 +64,13 @@ int bch2_quota_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (k.k->p.inode >= QTYP_NR) { if (k.k->p.inode >= QTYP_NR) {
prt_printf(err, "invalid quota type (%llu >= %u)", prt_printf(err, "invalid quota type (%llu >= %u)",
k.k->p.inode, QTYP_NR); k.k->p.inode, QTYP_NR);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (bkey_val_bytes(k.k) != sizeof(struct bch_quota)) { if (bkey_val_bytes(k.k) != sizeof(struct bch_quota)) {
prt_printf(err, "incorrect value size (%zu != %zu)", prt_printf(err, "incorrect value size (%zu != %zu)",
bkey_val_bytes(k.k), sizeof(struct bch_quota)); bkey_val_bytes(k.k), sizeof(struct bch_quota));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
......
...@@ -85,7 +85,7 @@ int bch2_reflink_v_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -85,7 +85,7 @@ int bch2_reflink_v_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_bytes(r.k) < sizeof(*r.v)) { if (bkey_val_bytes(r.k) < sizeof(*r.v)) {
prt_printf(err, "incorrect value size (%zu < %zu)", prt_printf(err, "incorrect value size (%zu < %zu)",
bkey_val_bytes(r.k), sizeof(*r.v)); bkey_val_bytes(r.k), sizeof(*r.v));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return bch2_bkey_ptrs_invalid(c, k, rw, err); return bch2_bkey_ptrs_invalid(c, k, rw, err);
...@@ -136,7 +136,7 @@ int bch2_indirect_inline_data_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -136,7 +136,7 @@ int bch2_indirect_inline_data_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_bytes(k.k) < sizeof(struct bch_indirect_inline_data)) { if (bkey_val_bytes(k.k) < sizeof(struct bch_indirect_inline_data)) {
prt_printf(err, "incorrect value size (%zu < %zu)", prt_printf(err, "incorrect value size (%zu < %zu)",
bkey_val_bytes(k.k), sizeof(struct bch_indirect_inline_data)); bkey_val_bytes(k.k), sizeof(struct bch_indirect_inline_data));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
......
...@@ -841,27 +841,27 @@ static int bch2_cpu_replicas_validate(struct bch_replicas_cpu *cpu_r, ...@@ -841,27 +841,27 @@ static int bch2_cpu_replicas_validate(struct bch_replicas_cpu *cpu_r,
if (e->data_type >= BCH_DATA_NR) { if (e->data_type >= BCH_DATA_NR) {
prt_printf(err, "invalid data type in entry "); prt_printf(err, "invalid data type in entry ");
bch2_replicas_entry_to_text(err, e); bch2_replicas_entry_to_text(err, e);
return -EINVAL; return -BCH_ERR_invalid_sb_replicas;
} }
if (!e->nr_devs) { if (!e->nr_devs) {
prt_printf(err, "no devices in entry "); prt_printf(err, "no devices in entry ");
bch2_replicas_entry_to_text(err, e); bch2_replicas_entry_to_text(err, e);
return -EINVAL; return -BCH_ERR_invalid_sb_replicas;
} }
if (e->nr_required > 1 && if (e->nr_required > 1 &&
e->nr_required >= e->nr_devs) { e->nr_required >= e->nr_devs) {
prt_printf(err, "bad nr_required in entry "); prt_printf(err, "bad nr_required in entry ");
bch2_replicas_entry_to_text(err, e); bch2_replicas_entry_to_text(err, e);
return -EINVAL; return -BCH_ERR_invalid_sb_replicas;
} }
for (j = 0; j < e->nr_devs; j++) for (j = 0; j < e->nr_devs; j++)
if (!bch2_dev_exists(sb, mi, e->devs[j])) { if (!bch2_dev_exists(sb, mi, e->devs[j])) {
prt_printf(err, "invalid device %u in entry ", e->devs[j]); prt_printf(err, "invalid device %u in entry ", e->devs[j]);
bch2_replicas_entry_to_text(err, e); bch2_replicas_entry_to_text(err, e);
return -EINVAL; return -BCH_ERR_invalid_sb_replicas;
} }
if (i + 1 < cpu_r->nr) { if (i + 1 < cpu_r->nr) {
...@@ -873,7 +873,7 @@ static int bch2_cpu_replicas_validate(struct bch_replicas_cpu *cpu_r, ...@@ -873,7 +873,7 @@ static int bch2_cpu_replicas_validate(struct bch_replicas_cpu *cpu_r,
if (!memcmp(e, n, cpu_r->entry_size)) { if (!memcmp(e, n, cpu_r->entry_size)) {
prt_printf(err, "duplicate replicas entry "); prt_printf(err, "duplicate replicas entry ");
bch2_replicas_entry_to_text(err, e); bch2_replicas_entry_to_text(err, e);
return -EINVAL; return -BCH_ERR_invalid_sb_replicas;
} }
} }
} }
......
...@@ -33,13 +33,13 @@ int bch2_snapshot_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -33,13 +33,13 @@ int bch2_snapshot_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_gt(k.k->p, POS(0, U32_MAX)) || if (bkey_gt(k.k->p, POS(0, U32_MAX)) ||
bkey_lt(k.k->p, POS(0, 1))) { bkey_lt(k.k->p, POS(0, 1))) {
prt_printf(err, "bad pos"); prt_printf(err, "bad pos");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (bkey_val_bytes(k.k) != sizeof(struct bch_snapshot)) { if (bkey_val_bytes(k.k) != sizeof(struct bch_snapshot)) {
prt_printf(err, "bad val size (%zu != %zu)", prt_printf(err, "bad val size (%zu != %zu)",
bkey_val_bytes(k.k), sizeof(struct bch_snapshot)); bkey_val_bytes(k.k), sizeof(struct bch_snapshot));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
s = bkey_s_c_to_snapshot(k); s = bkey_s_c_to_snapshot(k);
...@@ -48,18 +48,18 @@ int bch2_snapshot_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -48,18 +48,18 @@ int bch2_snapshot_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (id && id <= k.k->p.offset) { if (id && id <= k.k->p.offset) {
prt_printf(err, "bad parent node (%u <= %llu)", prt_printf(err, "bad parent node (%u <= %llu)",
id, k.k->p.offset); id, k.k->p.offset);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (le32_to_cpu(s.v->children[0]) < le32_to_cpu(s.v->children[1])) { if (le32_to_cpu(s.v->children[0]) < le32_to_cpu(s.v->children[1])) {
prt_printf(err, "children not normalized"); prt_printf(err, "children not normalized");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (s.v->children[0] && if (s.v->children[0] &&
s.v->children[0] == s.v->children[1]) { s.v->children[0] == s.v->children[1]) {
prt_printf(err, "duplicate child nodes"); prt_printf(err, "duplicate child nodes");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
...@@ -68,7 +68,7 @@ int bch2_snapshot_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -68,7 +68,7 @@ int bch2_snapshot_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (id >= k.k->p.offset) { if (id >= k.k->p.offset) {
prt_printf(err, "bad child node (%u >= %llu)", prt_printf(err, "bad child node (%u >= %llu)",
id, k.k->p.offset); id, k.k->p.offset);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
} }
...@@ -773,13 +773,13 @@ int bch2_subvolume_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -773,13 +773,13 @@ int bch2_subvolume_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_lt(k.k->p, SUBVOL_POS_MIN) || if (bkey_lt(k.k->p, SUBVOL_POS_MIN) ||
bkey_gt(k.k->p, SUBVOL_POS_MAX)) { bkey_gt(k.k->p, SUBVOL_POS_MAX)) {
prt_printf(err, "invalid pos"); prt_printf(err, "invalid pos");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (bkey_val_bytes(k.k) != sizeof(struct bch_subvolume)) { if (bkey_val_bytes(k.k) != sizeof(struct bch_subvolume)) {
prt_printf(err, "incorrect value size (%zu != %zu)", prt_printf(err, "incorrect value size (%zu != %zu)",
bkey_val_bytes(k.k), sizeof(struct bch_subvolume)); bkey_val_bytes(k.k), sizeof(struct bch_subvolume));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
......
...@@ -216,23 +216,23 @@ static int validate_sb_layout(struct bch_sb_layout *layout, struct printbuf *out ...@@ -216,23 +216,23 @@ static int validate_sb_layout(struct bch_sb_layout *layout, struct printbuf *out
if (!uuid_equal(&layout->magic, &BCACHE_MAGIC) && if (!uuid_equal(&layout->magic, &BCACHE_MAGIC) &&
!uuid_equal(&layout->magic, &BCHFS_MAGIC)) { !uuid_equal(&layout->magic, &BCHFS_MAGIC)) {
prt_printf(out, "Not a bcachefs superblock layout"); prt_printf(out, "Not a bcachefs superblock layout");
return -EINVAL; return -BCH_ERR_invalid_sb_layout;
} }
if (layout->layout_type != 0) { if (layout->layout_type != 0) {
prt_printf(out, "Invalid superblock layout type %u", prt_printf(out, "Invalid superblock layout type %u",
layout->layout_type); layout->layout_type);
return -EINVAL; return -BCH_ERR_invalid_sb_layout_type;
} }
if (!layout->nr_superblocks) { if (!layout->nr_superblocks) {
prt_printf(out, "Invalid superblock layout: no superblocks"); prt_printf(out, "Invalid superblock layout: no superblocks");
return -EINVAL; return -BCH_ERR_invalid_sb_layout_nr_superblocks;
} }
if (layout->nr_superblocks > ARRAY_SIZE(layout->sb_offset)) { if (layout->nr_superblocks > ARRAY_SIZE(layout->sb_offset)) {
prt_printf(out, "Invalid superblock layout: too many superblocks"); prt_printf(out, "Invalid superblock layout: too many superblocks");
return -EINVAL; return -BCH_ERR_invalid_sb_layout_nr_superblocks;
} }
max_sectors = 1 << layout->sb_max_size_bits; max_sectors = 1 << layout->sb_max_size_bits;
...@@ -246,7 +246,7 @@ static int validate_sb_layout(struct bch_sb_layout *layout, struct printbuf *out ...@@ -246,7 +246,7 @@ static int validate_sb_layout(struct bch_sb_layout *layout, struct printbuf *out
prt_printf(out, "Invalid superblock layout: superblocks overlap\n" prt_printf(out, "Invalid superblock layout: superblocks overlap\n"
" (sb %u ends at %llu next starts at %llu", " (sb %u ends at %llu next starts at %llu",
i - 1, prev_offset + max_sectors, offset); i - 1, prev_offset + max_sectors, offset);
return -EINVAL; return -BCH_ERR_invalid_sb_layout_superblocks_overlap;
} }
prev_offset = offset; prev_offset = offset;
} }
...@@ -273,25 +273,25 @@ static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out, ...@@ -273,25 +273,25 @@ static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out,
if (version >= bcachefs_metadata_version_max) { if (version >= bcachefs_metadata_version_max) {
prt_printf(out, "Unsupported superblock version %u (min %u, max %u)", prt_printf(out, "Unsupported superblock version %u (min %u, max %u)",
version, bcachefs_metadata_version_min, bcachefs_metadata_version_max); version, bcachefs_metadata_version_min, bcachefs_metadata_version_max);
return -EINVAL; return -BCH_ERR_invalid_sb_version;
} }
if (version_min < bcachefs_metadata_version_min) { if (version_min < bcachefs_metadata_version_min) {
prt_printf(out, "Unsupported superblock version %u (min %u, max %u)", prt_printf(out, "Unsupported superblock version %u (min %u, max %u)",
version_min, bcachefs_metadata_version_min, bcachefs_metadata_version_max); version_min, bcachefs_metadata_version_min, bcachefs_metadata_version_max);
return -EINVAL; return -BCH_ERR_invalid_sb_version;
} }
if (version_min > version) { if (version_min > version) {
prt_printf(out, "Bad minimum version %u, greater than version field %u", prt_printf(out, "Bad minimum version %u, greater than version field %u",
version_min, version); version_min, version);
return -EINVAL; return -BCH_ERR_invalid_sb_version;
} }
if (sb->features[1] || if (sb->features[1] ||
(le64_to_cpu(sb->features[0]) & (~0ULL << BCH_FEATURE_NR))) { (le64_to_cpu(sb->features[0]) & (~0ULL << BCH_FEATURE_NR))) {
prt_printf(out, "Filesystem has incompatible features"); prt_printf(out, "Filesystem has incompatible features");
return -EINVAL; return -BCH_ERR_invalid_sb_features;
} }
block_size = le16_to_cpu(sb->block_size); block_size = le16_to_cpu(sb->block_size);
...@@ -299,37 +299,37 @@ static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out, ...@@ -299,37 +299,37 @@ static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out,
if (block_size > PAGE_SECTORS) { if (block_size > PAGE_SECTORS) {
prt_printf(out, "Block size too big (got %u, max %u)", prt_printf(out, "Block size too big (got %u, max %u)",
block_size, PAGE_SECTORS); block_size, PAGE_SECTORS);
return -EINVAL; return -BCH_ERR_invalid_sb_block_size;
} }
if (bch2_is_zero(sb->user_uuid.b, sizeof(sb->user_uuid))) { if (bch2_is_zero(sb->user_uuid.b, sizeof(sb->user_uuid))) {
prt_printf(out, "Bad user UUID (got zeroes)"); prt_printf(out, "Bad user UUID (got zeroes)");
return -EINVAL; return -BCH_ERR_invalid_sb_uuid;
} }
if (bch2_is_zero(sb->uuid.b, sizeof(sb->uuid))) { if (bch2_is_zero(sb->uuid.b, sizeof(sb->uuid))) {
prt_printf(out, "Bad intenal UUID (got zeroes)"); prt_printf(out, "Bad intenal UUID (got zeroes)");
return -EINVAL; return -BCH_ERR_invalid_sb_uuid;
} }
if (!sb->nr_devices || if (!sb->nr_devices ||
sb->nr_devices > BCH_SB_MEMBERS_MAX) { sb->nr_devices > BCH_SB_MEMBERS_MAX) {
prt_printf(out, "Bad number of member devices %u (max %u)", prt_printf(out, "Bad number of member devices %u (max %u)",
sb->nr_devices, BCH_SB_MEMBERS_MAX); sb->nr_devices, BCH_SB_MEMBERS_MAX);
return -EINVAL; return -BCH_ERR_invalid_sb_too_many_members;
} }
if (sb->dev_idx >= sb->nr_devices) { if (sb->dev_idx >= sb->nr_devices) {
prt_printf(out, "Bad dev_idx (got %u, nr_devices %u)", prt_printf(out, "Bad dev_idx (got %u, nr_devices %u)",
sb->dev_idx, sb->nr_devices); sb->dev_idx, sb->nr_devices);
return -EINVAL; return -BCH_ERR_invalid_sb_dev_idx;
} }
if (!sb->time_precision || if (!sb->time_precision ||
le32_to_cpu(sb->time_precision) > NSEC_PER_SEC) { le32_to_cpu(sb->time_precision) > NSEC_PER_SEC) {
prt_printf(out, "Invalid time precision: %u (min 1, max %lu)", prt_printf(out, "Invalid time precision: %u (min 1, max %lu)",
le32_to_cpu(sb->time_precision), NSEC_PER_SEC); le32_to_cpu(sb->time_precision), NSEC_PER_SEC);
return -EINVAL; return -BCH_ERR_invalid_sb_time_precision;
} }
if (rw == READ) { if (rw == READ) {
...@@ -366,15 +366,15 @@ static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out, ...@@ -366,15 +366,15 @@ static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out,
vstruct_for_each(sb, f) { vstruct_for_each(sb, f) {
if (!f->u64s) { if (!f->u64s) {
prt_printf(out, "Invalid superblock: optional with size 0 (type %u)", prt_printf(out, "Invalid superblock: optional field with size 0 (type %u)",
le32_to_cpu(f->type)); le32_to_cpu(f->type));
return -EINVAL; return -BCH_ERR_invalid_sb_field_size;
} }
if (vstruct_next(f) > vstruct_last(sb)) { if (vstruct_next(f) > vstruct_last(sb)) {
prt_printf(out, "Invalid superblock: optional field extends past end of superblock (type %u)", prt_printf(out, "Invalid superblock: optional field extends past end of superblock (type %u)",
le32_to_cpu(f->type)); le32_to_cpu(f->type));
return -EINVAL; return -BCH_ERR_invalid_sb_field_size;
} }
} }
...@@ -382,7 +382,7 @@ static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out, ...@@ -382,7 +382,7 @@ static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out,
mi = bch2_sb_get_members(sb); mi = bch2_sb_get_members(sb);
if (!mi) { if (!mi) {
prt_printf(out, "Invalid superblock: member info area missing"); prt_printf(out, "Invalid superblock: member info area missing");
return -EINVAL; return -BCH_ERR_invalid_sb_members_missing;
} }
ret = bch2_sb_field_validate(sb, &mi->field, out); ret = bch2_sb_field_validate(sb, &mi->field, out);
...@@ -544,7 +544,7 @@ static int read_one_super(struct bch_sb_handle *sb, u64 offset, struct printbuf ...@@ -544,7 +544,7 @@ static int read_one_super(struct bch_sb_handle *sb, u64 offset, struct printbuf
if (!uuid_equal(&sb->sb->magic, &BCACHE_MAGIC) && if (!uuid_equal(&sb->sb->magic, &BCACHE_MAGIC) &&
!uuid_equal(&sb->sb->magic, &BCHFS_MAGIC)) { !uuid_equal(&sb->sb->magic, &BCHFS_MAGIC)) {
prt_printf(err, "Not a bcachefs superblock"); prt_printf(err, "Not a bcachefs superblock");
return -EINVAL; return -BCH_ERR_invalid_sb_magic;
} }
version = le16_to_cpu(sb->sb->version); version = le16_to_cpu(sb->sb->version);
...@@ -555,13 +555,13 @@ static int read_one_super(struct bch_sb_handle *sb, u64 offset, struct printbuf ...@@ -555,13 +555,13 @@ static int read_one_super(struct bch_sb_handle *sb, u64 offset, struct printbuf
if (version >= bcachefs_metadata_version_max) { if (version >= bcachefs_metadata_version_max) {
prt_printf(err, "Unsupported superblock version %u (min %u, max %u)", prt_printf(err, "Unsupported superblock version %u (min %u, max %u)",
version, bcachefs_metadata_version_min, bcachefs_metadata_version_max); version, bcachefs_metadata_version_min, bcachefs_metadata_version_max);
return -EINVAL; return -BCH_ERR_invalid_sb_version;
} }
if (version_min < bcachefs_metadata_version_min) { if (version_min < bcachefs_metadata_version_min) {
prt_printf(err, "Unsupported superblock version %u (min %u, max %u)", prt_printf(err, "Unsupported superblock version %u (min %u, max %u)",
version_min, bcachefs_metadata_version_min, bcachefs_metadata_version_max); version_min, bcachefs_metadata_version_min, bcachefs_metadata_version_max);
return -EINVAL; return -BCH_ERR_invalid_sb_version;
} }
bytes = vstruct_bytes(sb->sb); bytes = vstruct_bytes(sb->sb);
...@@ -569,7 +569,7 @@ static int read_one_super(struct bch_sb_handle *sb, u64 offset, struct printbuf ...@@ -569,7 +569,7 @@ static int read_one_super(struct bch_sb_handle *sb, u64 offset, struct printbuf
if (bytes > 512 << sb->sb->layout.sb_max_size_bits) { if (bytes > 512 << sb->sb->layout.sb_max_size_bits) {
prt_printf(err, "Invalid superblock: too big (got %zu bytes, layout max %lu)", prt_printf(err, "Invalid superblock: too big (got %zu bytes, layout max %lu)",
bytes, 512UL << sb->sb->layout.sb_max_size_bits); bytes, 512UL << sb->sb->layout.sb_max_size_bits);
return -EINVAL; return -BCH_ERR_invalid_sb_too_big;
} }
if (bytes > sb->buffer_size) { if (bytes > sb->buffer_size) {
...@@ -580,7 +580,7 @@ static int read_one_super(struct bch_sb_handle *sb, u64 offset, struct printbuf ...@@ -580,7 +580,7 @@ static int read_one_super(struct bch_sb_handle *sb, u64 offset, struct printbuf
if (BCH_SB_CSUM_TYPE(sb->sb) >= BCH_CSUM_NR) { if (BCH_SB_CSUM_TYPE(sb->sb) >= BCH_CSUM_NR) {
prt_printf(err, "unknown checksum type %llu", BCH_SB_CSUM_TYPE(sb->sb)); prt_printf(err, "unknown checksum type %llu", BCH_SB_CSUM_TYPE(sb->sb));
return -EINVAL; return -BCH_ERR_invalid_sb_csum_type;
} }
/* XXX: verify MACs */ /* XXX: verify MACs */
...@@ -589,7 +589,7 @@ static int read_one_super(struct bch_sb_handle *sb, u64 offset, struct printbuf ...@@ -589,7 +589,7 @@ static int read_one_super(struct bch_sb_handle *sb, u64 offset, struct printbuf
if (bch2_crc_cmp(csum, sb->sb->csum)) { if (bch2_crc_cmp(csum, sb->sb->csum)) {
prt_printf(err, "bad checksum"); prt_printf(err, "bad checksum");
return -EINVAL; return -BCH_ERR_invalid_sb_csum;
} }
sb->seq = le64_to_cpu(sb->sb->seq); sb->seq = le64_to_cpu(sb->sb->seq);
...@@ -703,7 +703,7 @@ int bch2_read_super(const char *path, struct bch_opts *opts, ...@@ -703,7 +703,7 @@ int bch2_read_super(const char *path, struct bch_opts *opts,
prt_printf(&err, "block size (%u) smaller than device block size (%u)", prt_printf(&err, "block size (%u) smaller than device block size (%u)",
le16_to_cpu(sb->sb->block_size) << 9, le16_to_cpu(sb->sb->block_size) << 9,
bdev_logical_block_size(sb->bdev)); bdev_logical_block_size(sb->bdev));
ret = -EINVAL; ret = -BCH_ERR_block_size_too_small;
goto err; goto err;
} }
...@@ -958,7 +958,7 @@ static int bch2_sb_members_validate(struct bch_sb *sb, ...@@ -958,7 +958,7 @@ static int bch2_sb_members_validate(struct bch_sb *sb,
if ((void *) (mi->members + sb->nr_devices) > if ((void *) (mi->members + sb->nr_devices) >
vstruct_end(&mi->field)) { vstruct_end(&mi->field)) {
prt_printf(err, "too many devices for section size"); prt_printf(err, "too many devices for section size");
return -EINVAL; return -BCH_ERR_invalid_sb_members;
} }
for (i = 0; i < sb->nr_devices; i++) { for (i = 0; i < sb->nr_devices; i++) {
...@@ -970,28 +970,28 @@ static int bch2_sb_members_validate(struct bch_sb *sb, ...@@ -970,28 +970,28 @@ static int bch2_sb_members_validate(struct bch_sb *sb,
if (le64_to_cpu(m->nbuckets) > LONG_MAX) { if (le64_to_cpu(m->nbuckets) > LONG_MAX) {
prt_printf(err, "device %u: too many buckets (got %llu, max %lu)", prt_printf(err, "device %u: too many buckets (got %llu, max %lu)",
i, le64_to_cpu(m->nbuckets), LONG_MAX); i, le64_to_cpu(m->nbuckets), LONG_MAX);
return -EINVAL; return -BCH_ERR_invalid_sb_members;
} }
if (le64_to_cpu(m->nbuckets) - if (le64_to_cpu(m->nbuckets) -
le16_to_cpu(m->first_bucket) < BCH_MIN_NR_NBUCKETS) { le16_to_cpu(m->first_bucket) < BCH_MIN_NR_NBUCKETS) {
prt_printf(err, "device %u: not enough buckets (got %llu, max %u)", prt_printf(err, "device %u: not enough buckets (got %llu, max %u)",
i, le64_to_cpu(m->nbuckets), BCH_MIN_NR_NBUCKETS); i, le64_to_cpu(m->nbuckets), BCH_MIN_NR_NBUCKETS);
return -EINVAL; return -BCH_ERR_invalid_sb_members;
} }
if (le16_to_cpu(m->bucket_size) < if (le16_to_cpu(m->bucket_size) <
le16_to_cpu(sb->block_size)) { le16_to_cpu(sb->block_size)) {
prt_printf(err, "device %u: bucket size %u smaller than block size %u", prt_printf(err, "device %u: bucket size %u smaller than block size %u",
i, le16_to_cpu(m->bucket_size), le16_to_cpu(sb->block_size)); i, le16_to_cpu(m->bucket_size), le16_to_cpu(sb->block_size));
return -EINVAL; return -BCH_ERR_invalid_sb_members;
} }
if (le16_to_cpu(m->bucket_size) < if (le16_to_cpu(m->bucket_size) <
BCH_SB_BTREE_NODE_SIZE(sb)) { BCH_SB_BTREE_NODE_SIZE(sb)) {
prt_printf(err, "device %u: bucket size %u smaller than btree node size %llu", prt_printf(err, "device %u: bucket size %u smaller than btree node size %llu",
i, le16_to_cpu(m->bucket_size), BCH_SB_BTREE_NODE_SIZE(sb)); i, le16_to_cpu(m->bucket_size), BCH_SB_BTREE_NODE_SIZE(sb));
return -EINVAL; return -BCH_ERR_invalid_sb_members;
} }
} }
...@@ -1123,12 +1123,12 @@ static int bch2_sb_crypt_validate(struct bch_sb *sb, ...@@ -1123,12 +1123,12 @@ static int bch2_sb_crypt_validate(struct bch_sb *sb,
if (vstruct_bytes(&crypt->field) < sizeof(*crypt)) { if (vstruct_bytes(&crypt->field) < sizeof(*crypt)) {
prt_printf(err, "wrong size (got %zu should be %zu)", prt_printf(err, "wrong size (got %zu should be %zu)",
vstruct_bytes(&crypt->field), sizeof(*crypt)); vstruct_bytes(&crypt->field), sizeof(*crypt));
return -EINVAL; return -BCH_ERR_invalid_sb_crypt;
} }
if (BCH_CRYPT_KDF_TYPE(crypt)) { if (BCH_CRYPT_KDF_TYPE(crypt)) {
prt_printf(err, "bad kdf type %llu", BCH_CRYPT_KDF_TYPE(crypt)); prt_printf(err, "bad kdf type %llu", BCH_CRYPT_KDF_TYPE(crypt));
return -EINVAL; return -BCH_ERR_invalid_sb_crypt;
} }
return 0; return 0;
...@@ -1365,7 +1365,7 @@ static int bch2_sb_clean_validate(struct bch_sb *sb, ...@@ -1365,7 +1365,7 @@ static int bch2_sb_clean_validate(struct bch_sb *sb,
if (vstruct_bytes(&clean->field) < sizeof(*clean)) { if (vstruct_bytes(&clean->field) < sizeof(*clean)) {
prt_printf(err, "wrong size (got %zu should be %zu)", prt_printf(err, "wrong size (got %zu should be %zu)",
vstruct_bytes(&clean->field), sizeof(*clean)); vstruct_bytes(&clean->field), sizeof(*clean));
return -EINVAL; return -BCH_ERR_invalid_sb_clean;
} }
return 0; return 0;
......
...@@ -880,7 +880,7 @@ int bch2_fs_start(struct bch_fs *c) ...@@ -880,7 +880,7 @@ int bch2_fs_start(struct bch_fs *c)
struct bch_dev *ca; struct bch_dev *ca;
time64_t now = ktime_get_real_seconds(); time64_t now = ktime_get_real_seconds();
unsigned i; unsigned i;
int ret = -EINVAL; int ret;
down_write(&c->state_lock); down_write(&c->state_lock);
...@@ -917,9 +917,9 @@ int bch2_fs_start(struct bch_fs *c) ...@@ -917,9 +917,9 @@ int bch2_fs_start(struct bch_fs *c)
if (ret) if (ret)
goto err; goto err;
ret = -EINVAL;
if (bch2_fs_init_fault("fs_start")) { if (bch2_fs_init_fault("fs_start")) {
bch_err(c, "fs_start fault injected"); bch_err(c, "fs_start fault injected");
ret = -EINVAL;
goto err; goto err;
} }
...@@ -942,46 +942,43 @@ int bch2_fs_start(struct bch_fs *c) ...@@ -942,46 +942,43 @@ int bch2_fs_start(struct bch_fs *c)
return ret; return ret;
err: err:
bch_err(c, "error starting filesystem: %s", bch2_err_str(ret)); bch_err(c, "error starting filesystem: %s", bch2_err_str(ret));
if (ret < -BCH_ERR_START)
ret = -EINVAL;
goto out; goto out;
} }
static const char *bch2_dev_may_add(struct bch_sb *sb, struct bch_fs *c) static int bch2_dev_may_add(struct bch_sb *sb, struct bch_fs *c)
{ {
struct bch_sb_field_members *sb_mi; struct bch_sb_field_members *sb_mi;
sb_mi = bch2_sb_get_members(sb); sb_mi = bch2_sb_get_members(sb);
if (!sb_mi) if (!sb_mi)
return "Invalid superblock: member info area missing"; return -BCH_ERR_member_info_missing;
if (le16_to_cpu(sb->block_size) != block_sectors(c)) if (le16_to_cpu(sb->block_size) != block_sectors(c))
return "mismatched block size"; return -BCH_ERR_mismatched_block_size;
if (le16_to_cpu(sb_mi->members[sb->dev_idx].bucket_size) < if (le16_to_cpu(sb_mi->members[sb->dev_idx].bucket_size) <
BCH_SB_BTREE_NODE_SIZE(c->disk_sb.sb)) BCH_SB_BTREE_NODE_SIZE(c->disk_sb.sb))
return "new cache bucket size is too small"; return -BCH_ERR_bucket_size_too_small;
return NULL; return 0;
} }
static const char *bch2_dev_in_fs(struct bch_sb *fs, struct bch_sb *sb) static int bch2_dev_in_fs(struct bch_sb *fs, struct bch_sb *sb)
{ {
struct bch_sb *newest = struct bch_sb *newest =
le64_to_cpu(fs->seq) > le64_to_cpu(sb->seq) ? fs : sb; le64_to_cpu(fs->seq) > le64_to_cpu(sb->seq) ? fs : sb;
struct bch_sb_field_members *mi = bch2_sb_get_members(newest); struct bch_sb_field_members *mi = bch2_sb_get_members(newest);
if (!uuid_equal(&fs->uuid, &sb->uuid)) if (!uuid_equal(&fs->uuid, &sb->uuid))
return "device not a member of filesystem"; return -BCH_ERR_device_not_a_member_of_filesystem;
if (!bch2_dev_exists(newest, mi, sb->dev_idx)) if (!bch2_dev_exists(newest, mi, sb->dev_idx))
return "device has been removed"; return -BCH_ERR_device_has_been_removed;
if (fs->block_size != sb->block_size) if (fs->block_size != sb->block_size)
return "mismatched block size"; return -BCH_ERR_mismatched_block_size;
return NULL; return 0;
} }
/* Device startup/shutdown: */ /* Device startup/shutdown: */
...@@ -1179,23 +1176,17 @@ static int __bch2_dev_attach_bdev(struct bch_dev *ca, struct bch_sb_handle *sb) ...@@ -1179,23 +1176,17 @@ static int __bch2_dev_attach_bdev(struct bch_dev *ca, struct bch_sb_handle *sb)
if (bch2_dev_is_online(ca)) { if (bch2_dev_is_online(ca)) {
bch_err(ca, "already have device online in slot %u", bch_err(ca, "already have device online in slot %u",
sb->sb->dev_idx); sb->sb->dev_idx);
return -EINVAL; return -BCH_ERR_device_already_online;
} }
if (get_capacity(sb->bdev->bd_disk) < if (get_capacity(sb->bdev->bd_disk) <
ca->mi.bucket_size * ca->mi.nbuckets) { ca->mi.bucket_size * ca->mi.nbuckets) {
bch_err(ca, "cannot online: device too small"); bch_err(ca, "cannot online: device too small");
return -EINVAL; return -BCH_ERR_device_size_too_small;
} }
BUG_ON(!percpu_ref_is_zero(&ca->io_ref)); BUG_ON(!percpu_ref_is_zero(&ca->io_ref));
if (get_capacity(sb->bdev->bd_disk) <
ca->mi.bucket_size * ca->mi.nbuckets) {
bch_err(ca, "device too small");
return -EINVAL;
}
ret = bch2_dev_journal_init(ca, sb->sb); ret = bch2_dev_journal_init(ca, sb->sb);
if (ret) if (ret)
return ret; return ret;
...@@ -1370,7 +1361,7 @@ int __bch2_dev_set_state(struct bch_fs *c, struct bch_dev *ca, ...@@ -1370,7 +1361,7 @@ int __bch2_dev_set_state(struct bch_fs *c, struct bch_dev *ca,
return 0; return 0;
if (!bch2_dev_state_allowed(c, ca, new_state, flags)) if (!bch2_dev_state_allowed(c, ca, new_state, flags))
return -EINVAL; return -BCH_ERR_device_state_not_allowed;
if (new_state != BCH_MEMBER_STATE_rw) if (new_state != BCH_MEMBER_STATE_rw)
__bch2_dev_read_only(c, ca); __bch2_dev_read_only(c, ca);
...@@ -1433,7 +1424,7 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags) ...@@ -1433,7 +1424,7 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags)
{ {
struct bch_sb_field_members *mi; struct bch_sb_field_members *mi;
unsigned dev_idx = ca->dev_idx, data; unsigned dev_idx = ca->dev_idx, data;
int ret = -EINVAL; int ret;
down_write(&c->state_lock); down_write(&c->state_lock);
...@@ -1445,6 +1436,7 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags) ...@@ -1445,6 +1436,7 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags)
if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_failed, flags)) { if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_failed, flags)) {
bch_err(ca, "Cannot remove without losing data"); bch_err(ca, "Cannot remove without losing data");
ret = -BCH_ERR_device_state_not_allowed;
goto err; goto err;
} }
...@@ -1530,7 +1522,6 @@ int bch2_dev_add(struct bch_fs *c, const char *path) ...@@ -1530,7 +1522,6 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
{ {
struct bch_opts opts = bch2_opts_empty(); struct bch_opts opts = bch2_opts_empty();
struct bch_sb_handle sb; struct bch_sb_handle sb;
const char *err;
struct bch_dev *ca = NULL; struct bch_dev *ca = NULL;
struct bch_sb_field_members *mi; struct bch_sb_field_members *mi;
struct bch_member dev_mi; struct bch_member dev_mi;
...@@ -1555,10 +1546,9 @@ int bch2_dev_add(struct bch_fs *c, const char *path) ...@@ -1555,10 +1546,9 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
} }
} }
err = bch2_dev_may_add(sb.sb, c); ret = bch2_dev_may_add(sb.sb, c);
if (err) { if (ret) {
bch_err(c, "device add error: %s", err); bch_err(c, "device add error: %s", bch2_err_str(ret));
ret = -EINVAL;
goto err; goto err;
} }
...@@ -1692,7 +1682,6 @@ int bch2_dev_online(struct bch_fs *c, const char *path) ...@@ -1692,7 +1682,6 @@ int bch2_dev_online(struct bch_fs *c, const char *path)
struct bch_sb_field_members *mi; struct bch_sb_field_members *mi;
struct bch_dev *ca; struct bch_dev *ca;
unsigned dev_idx; unsigned dev_idx;
const char *err;
int ret; int ret;
down_write(&c->state_lock); down_write(&c->state_lock);
...@@ -1705,9 +1694,9 @@ int bch2_dev_online(struct bch_fs *c, const char *path) ...@@ -1705,9 +1694,9 @@ int bch2_dev_online(struct bch_fs *c, const char *path)
dev_idx = sb.sb->dev_idx; dev_idx = sb.sb->dev_idx;
err = bch2_dev_in_fs(c->disk_sb.sb, sb.sb); ret = bch2_dev_in_fs(c->disk_sb.sb, sb.sb);
if (err) { if (ret) {
bch_err(c, "error bringing %s online: %s", path, err); bch_err(c, "error bringing %s online: %s", path, bch2_err_str(ret));
goto err; goto err;
} }
...@@ -1741,7 +1730,7 @@ int bch2_dev_online(struct bch_fs *c, const char *path) ...@@ -1741,7 +1730,7 @@ int bch2_dev_online(struct bch_fs *c, const char *path)
err: err:
up_write(&c->state_lock); up_write(&c->state_lock);
bch2_free_super(&sb); bch2_free_super(&sb);
return -EINVAL; return ret;
} }
int bch2_dev_offline(struct bch_fs *c, struct bch_dev *ca, int flags) int bch2_dev_offline(struct bch_fs *c, struct bch_dev *ca, int flags)
...@@ -1757,7 +1746,7 @@ int bch2_dev_offline(struct bch_fs *c, struct bch_dev *ca, int flags) ...@@ -1757,7 +1746,7 @@ int bch2_dev_offline(struct bch_fs *c, struct bch_dev *ca, int flags)
if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_failed, flags)) { if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_failed, flags)) {
bch_err(ca, "Cannot offline required disk"); bch_err(ca, "Cannot offline required disk");
up_write(&c->state_lock); up_write(&c->state_lock);
return -EINVAL; return -BCH_ERR_device_state_not_allowed;
} }
__bch2_dev_offline(c, ca); __bch2_dev_offline(c, ca);
...@@ -1783,7 +1772,7 @@ int bch2_dev_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets) ...@@ -1783,7 +1772,7 @@ int bch2_dev_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets)
get_capacity(ca->disk_sb.bdev->bd_disk) < get_capacity(ca->disk_sb.bdev->bd_disk) <
ca->mi.bucket_size * nbuckets) { ca->mi.bucket_size * nbuckets) {
bch_err(ca, "New size larger than device"); bch_err(ca, "New size larger than device");
ret = -EINVAL; ret = -BCH_ERR_device_size_too_small;
goto err; goto err;
} }
...@@ -1836,7 +1825,6 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices, ...@@ -1836,7 +1825,6 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices,
struct bch_fs *c = NULL; struct bch_fs *c = NULL;
struct bch_sb_field_members *mi; struct bch_sb_field_members *mi;
unsigned i, best_sb = 0; unsigned i, best_sb = 0;
const char *err;
struct printbuf errbuf = PRINTBUF; struct printbuf errbuf = PRINTBUF;
int ret = 0; int ret = 0;
...@@ -1880,8 +1868,8 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices, ...@@ -1880,8 +1868,8 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices,
continue; continue;
} }
err = bch2_dev_in_fs(sb[best_sb].sb, sb[i].sb); ret = bch2_dev_in_fs(sb[best_sb].sb, sb[i].sb);
if (err) if (ret)
goto err_print; goto err_print;
i++; i++;
} }
...@@ -1902,9 +1890,10 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices, ...@@ -1902,9 +1890,10 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices,
} }
up_write(&c->state_lock); up_write(&c->state_lock);
err = "insufficient devices"; if (!bch2_fs_may_start(c)) {
if (!bch2_fs_may_start(c)) ret = -BCH_ERR_insufficient_devices_to_start;
goto err_print; goto err_print;
}
if (!c->opts.nostart) { if (!c->opts.nostart) {
ret = bch2_fs_start(c); ret = bch2_fs_start(c);
...@@ -1919,8 +1908,7 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices, ...@@ -1919,8 +1908,7 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices,
return c; return c;
err_print: err_print:
pr_err("bch_fs_open err opening %s: %s", pr_err("bch_fs_open err opening %s: %s",
devices[0], err); devices[0], bch2_err_str(ret));
ret = -EINVAL;
err: err:
if (!IS_ERR_OR_NULL(c)) if (!IS_ERR_OR_NULL(c))
bch2_fs_stop(c); bch2_fs_stop(c);
......
...@@ -78,7 +78,7 @@ int bch2_xattr_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -78,7 +78,7 @@ int bch2_xattr_invalid(const struct bch_fs *c, struct bkey_s_c k,
if (bkey_val_bytes(k.k) < sizeof(struct bch_xattr)) { if (bkey_val_bytes(k.k) < sizeof(struct bch_xattr)) {
prt_printf(err, "incorrect value size (%zu < %zu)", prt_printf(err, "incorrect value size (%zu < %zu)",
bkey_val_bytes(k.k), sizeof(*xattr.v)); bkey_val_bytes(k.k), sizeof(*xattr.v));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (bkey_val_u64s(k.k) < if (bkey_val_u64s(k.k) <
...@@ -88,7 +88,7 @@ int bch2_xattr_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -88,7 +88,7 @@ int bch2_xattr_invalid(const struct bch_fs *c, struct bkey_s_c k,
bkey_val_u64s(k.k), bkey_val_u64s(k.k),
xattr_val_u64s(xattr.v->x_name_len, xattr_val_u64s(xattr.v->x_name_len,
le16_to_cpu(xattr.v->x_val_len))); le16_to_cpu(xattr.v->x_val_len)));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
/* XXX why +4 ? */ /* XXX why +4 ? */
...@@ -99,18 +99,18 @@ int bch2_xattr_invalid(const struct bch_fs *c, struct bkey_s_c k, ...@@ -99,18 +99,18 @@ int bch2_xattr_invalid(const struct bch_fs *c, struct bkey_s_c k,
bkey_val_u64s(k.k), bkey_val_u64s(k.k),
xattr_val_u64s(xattr.v->x_name_len, xattr_val_u64s(xattr.v->x_name_len,
le16_to_cpu(xattr.v->x_val_len) + 4)); le16_to_cpu(xattr.v->x_val_len) + 4));
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
handler = bch2_xattr_type_to_handler(xattr.v->x_type); handler = bch2_xattr_type_to_handler(xattr.v->x_type);
if (!handler) { if (!handler) {
prt_printf(err, "invalid type (%u)", xattr.v->x_type); prt_printf(err, "invalid type (%u)", xattr.v->x_type);
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
if (memchr(xattr.v->x_name, '\0', xattr.v->x_name_len)) { if (memchr(xattr.v->x_name, '\0', xattr.v->x_name_len)) {
prt_printf(err, "xattr name has invalid characters"); prt_printf(err, "xattr name has invalid characters");
return -EINVAL; return -BCH_ERR_invalid_bkey;
} }
return 0; return 0;
......
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