Commit e47a390a authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Convert -ENOENT to private error codes

As with previous conversions, replace -ENOENT uses with more informative
private error codes.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent f154c3eb
......@@ -236,7 +236,7 @@ struct posix_acl *bch2_get_acl(struct mnt_idmap *idmap,
if (ret) {
if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
goto retry;
if (ret != -ENOENT)
if (!bch2_err_matches(ret, ENOENT))
acl = ERR_PTR(ret);
goto out;
}
......@@ -287,7 +287,7 @@ int bch2_set_acl_trans(struct btree_trans *trans, subvol_inum inum,
inum, &search);
}
return ret == -ENOENT ? 0 : ret;
return bch2_err_matches(ret, ENOENT) ? 0 : ret;
}
int bch2_set_acl(struct mnt_idmap *idmap,
......@@ -368,7 +368,7 @@ int bch2_acl_chmod(struct btree_trans *trans, subvol_inum inum,
&X_SEARCH(KEY_TYPE_XATTR_INDEX_POSIX_ACL_ACCESS, "", 0),
BTREE_ITER_INTENT);
if (ret)
return ret == -ENOENT ? 0 : ret;
return bch2_err_matches(ret, ENOENT) ? 0 : ret;
k = bch2_btree_iter_peek_slot(&iter);
xattr = bkey_s_c_to_xattr(k);
......
......@@ -516,7 +516,7 @@ static inline struct bkey_s_c __bch2_bkey_get_iter(struct btree_trans *trans,
k = bch2_btree_iter_peek_slot(iter);
if (!bkey_err(k) && type && k.k->type != type)
k = bkey_s_c_err(-ENOENT);
k = bkey_s_c_err(-BCH_ERR_ENOENT_bkey_type_mismatch);
if (unlikely(bkey_err(k)))
bch2_trans_iter_exit(trans, iter);
return k;
......
......@@ -1455,7 +1455,7 @@ static int bch2_trans_mark_stripe_ptr(struct btree_trans *trans,
BTREE_ITER_WITH_UPDATES, stripe);
ret = PTR_ERR_OR_ZERO(s);
if (unlikely(ret)) {
bch2_trans_inconsistent_on(ret == -ENOENT, trans,
bch2_trans_inconsistent_on(bch2_err_matches(ret, ENOENT), trans,
"pointer to nonexistent stripe %llu",
(u64) p.ec.idx);
goto err;
......
......@@ -578,7 +578,7 @@ static long bch2_ioctl_disk_get_idx(struct bch_fs *c,
return i;
}
return -ENOENT;
return -BCH_ERR_ENOENT_dev_idx_not_found;
}
static long bch2_ioctl_disk_resize(struct bch_fs *c,
......
......@@ -94,6 +94,17 @@
x(ENOSPC, ENOSPC_sb_crypt) \
x(ENOSPC, ENOSPC_btree_slot) \
x(ENOSPC, ENOSPC_snapshot_tree) \
x(ENOENT, ENOENT_bkey_type_mismatch) \
x(ENOENT, ENOENT_str_hash_lookup) \
x(ENOENT, ENOENT_str_hash_set_must_replace) \
x(ENOENT, ENOENT_inode) \
x(ENOENT, ENOENT_not_subvol) \
x(ENOENT, ENOENT_directory_dead) \
x(ENOENT, ENOENT_subvolume) \
x(ENOENT, ENOENT_snapshot_tree) \
x(ENOENT, ENOENT_dirent_doesnt_match_inode) \
x(ENOENT, ENOENT_dev_not_found) \
x(ENOENT, ENOENT_dev_idx_not_found) \
x(0, open_buckets_empty) \
x(0, freelist_empty) \
x(BCH_ERR_freelist_empty, no_buckets_found) \
......
......@@ -281,7 +281,7 @@ int bch2_unlink_trans(struct btree_trans *trans,
}
if (deleting_snapshot && !inode_u->bi_subvol) {
ret = -ENOENT;
ret = -BCH_ERR_ENOENT_not_subvol;
goto err;
}
......
......@@ -382,7 +382,7 @@ static long bch2_ioctl_subvolume_create(struct bch_fs *c, struct file *filp,
dir = dst_path.dentry->d_inode;
if (IS_DEADDIR(dir)) {
error = -ENOENT;
error = -BCH_ERR_ENOENT_directory_dead;
goto err3;
}
......
......@@ -105,7 +105,7 @@ int __must_check bch2_write_inode(struct bch_fs *c,
if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
goto retry;
bch2_fs_fatal_err_on(ret == -ENOENT, c,
bch2_fs_fatal_err_on(bch2_err_matches(ret, ENOENT), c,
"inode %u:%llu not found when updating",
inode_inum(inode).subvol,
inode_inum(inode).inum);
......@@ -1261,14 +1261,14 @@ static int bch2_get_name(struct dentry *parent, char *name, struct dentry *child
goto err;
if (k.k->type != KEY_TYPE_dirent) {
ret = -ENOENT;
ret = -BCH_ERR_ENOENT_dirent_doesnt_match_inode;
goto err;
}
d = bkey_s_c_to_dirent(k);
ret = bch2_dirent_read_target(&trans, inode_inum(dir), d, &target);
if (ret > 0)
ret = -ENOENT;
ret = -BCH_ERR_ENOENT_dirent_doesnt_match_inode;
if (ret)
goto err;
......
......@@ -78,7 +78,7 @@ static int __snapshot_lookup_subvol(struct btree_trans *trans, u32 snapshot,
snapshot, &s);
if (!ret)
*subvol = le32_to_cpu(s.subvol);
else if (ret == -ENOENT)
else if (bch2_err_matches(ret, ENOENT))
bch_err(trans->c, "snapshot %u not fonud", snapshot);
return ret;
......@@ -119,7 +119,7 @@ static int lookup_first_inode(struct btree_trans *trans, u64 inode_nr,
goto err;
if (!k.k || !bkey_eq(k.k->p, POS(0, inode_nr))) {
ret = -ENOENT;
ret = -BCH_ERR_ENOENT_inode;
goto err;
}
......@@ -148,7 +148,7 @@ static int __lookup_inode(struct btree_trans *trans, u64 inode_nr,
ret = bkey_is_inode(k.k)
? bch2_inode_unpack(k, inode)
: -ENOENT;
: -BCH_ERR_ENOENT_inode;
if (!ret)
*snapshot = iter.pos.snapshot;
err:
......@@ -333,7 +333,7 @@ static int lookup_lostfound(struct btree_trans *trans, u32 subvol,
ret = __lookup_dirent(trans, root_hash_info, root_inum,
&lostfound_str, &inum, &d_type);
if (ret == -ENOENT) {
if (bch2_err_matches(ret, ENOENT)) {
bch_notice(c, "creating lost+found");
goto create_lostfound;
}
......@@ -1088,7 +1088,7 @@ static int inode_backpointer_exists(struct btree_trans *trans,
SPOS(inode->bi_dir, inode->bi_dir_offset, snapshot));
ret = bkey_err(d);
if (ret)
return ret == -ENOENT ? 0 : ret;
return bch2_err_matches(ret, ENOENT) ? 0 : ret;
ret = dirent_points_to_inode(d, inode);
bch2_trans_iter_exit(trans, &iter);
......@@ -1653,7 +1653,7 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter,
ret = __subvol_lookup(trans, target_subvol,
&target_snapshot, &target_inum);
if (ret && ret != -ENOENT)
if (ret && !bch2_err_matches(ret, ENOENT))
goto err;
if (fsck_err_on(ret, c,
......@@ -1665,7 +1665,7 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter,
ret = __lookup_inode(trans, target_inum,
&subvol_root, &target_snapshot);
if (ret && ret != -ENOENT)
if (ret && !bch2_err_matches(ret, ENOENT))
goto err;
if (fsck_err_on(ret, c,
......@@ -1846,7 +1846,7 @@ static int check_root_trans(struct btree_trans *trans)
int ret;
ret = __subvol_lookup(trans, BCACHEFS_ROOT_SUBVOL, &snapshot, &inum);
if (ret && ret != -ENOENT)
if (ret && !bch2_err_matches(ret, ENOENT))
return ret;
if (mustfix_fsck_err_on(ret, c, "root subvol missing")) {
......@@ -1873,7 +1873,7 @@ static int check_root_trans(struct btree_trans *trans)
}
ret = __lookup_inode(trans, BCACHEFS_ROOT_INO, &root_inode, &snapshot);
if (ret && ret != -ENOENT)
if (ret && !bch2_err_matches(ret, ENOENT))
return ret;
if (mustfix_fsck_err_on(ret, c, "root directory missing") ||
......@@ -1972,15 +1972,15 @@ static int check_path(struct btree_trans *trans,
PTR_ERR_OR_ZERO((d = dirent_get_by_pos(trans, &dirent_iter,
SPOS(inode->bi_dir, inode->bi_dir_offset,
parent_snapshot))).k));
if (ret && ret != -ENOENT)
if (ret && !bch2_err_matches(ret, ENOENT))
break;
if (!ret && !dirent_points_to_inode(d, inode)) {
bch2_trans_iter_exit(trans, &dirent_iter);
ret = -ENOENT;
ret = -BCH_ERR_ENOENT_dirent_doesnt_match_inode;
}
if (ret == -ENOENT) {
if (bch2_err_matches(ret, ENOENT)) {
if (fsck_err(c, "unreachable inode %llu:%u, type %s nlink %u backptr %llu:%llu",
inode->bi_inum, snapshot,
bch2_d_type_str(inode_d_type(inode)),
......
......@@ -336,7 +336,7 @@ int bch2_inode_peek(struct btree_trans *trans,
if (ret)
return ret;
ret = bkey_is_inode(k.k) ? 0 : -ENOENT;
ret = bkey_is_inode(k.k) ? 0 : -BCH_ERR_ENOENT_inode;
if (ret)
goto err;
......
......@@ -427,7 +427,7 @@ static int lookup_inode(struct btree_trans *trans, struct bpos pos,
goto err;
if (!k.k || !bkey_eq(k.k->p, pos)) {
ret = -ENOENT;
ret = -BCH_ERR_ENOENT_inode;
goto err;
}
......
......@@ -236,7 +236,7 @@ static int bch2_copygc(struct btree_trans *trans,
darray_exit(&buckets);
/* no entries in LRU btree found, or got to end: */
if (ret == -ENOENT)
if (bch2_err_matches(ret, ENOENT))
ret = 0;
if (ret < 0 && !bch2_err_matches(ret, EROFS))
......
......@@ -900,7 +900,7 @@ static int bch2_get_next_quota(struct super_block *sb, struct kqid *kqid,
ret = -ENOENT;
found:
mutex_unlock(&q->lock);
return ret;
return bch2_err_class(ret);
}
static int bch2_set_quota_trans(struct btree_trans *trans,
......@@ -960,7 +960,7 @@ static int bch2_set_quota(struct super_block *sb, struct kqid qid,
bch2_set_quota_trans(&trans, &new_quota, qdq)) ?:
__bch2_quota_set(c, bkey_i_to_s_c(&new_quota.k_i), qdq);
return ret;
return bch2_err_class(ret);
}
const struct quotactl_ops bch2_quotactl_operations = {
......
......@@ -1082,7 +1082,7 @@ static int bch2_fs_upgrade_for_subvolumes(struct btree_trans *trans)
if (!bkey_is_inode(k.k)) {
bch_err(trans->c, "root inode not found");
ret = -ENOENT;
ret = -BCH_ERR_ENOENT_inode;
goto err;
}
......
......@@ -181,7 +181,7 @@ bch2_hash_lookup(struct btree_trans *trans,
}
bch2_trans_iter_exit(trans, iter);
return ret ?: -ENOENT;
return ret ?: -BCH_ERR_ENOENT_str_hash_lookup;
}
static __always_inline int
......@@ -288,7 +288,7 @@ int bch2_hash_set_snapshot(struct btree_trans *trans,
not_found:
if (!found && (flags & BCH_HASH_SET_MUST_REPLACE)) {
ret = -ENOENT;
ret = -BCH_ERR_ENOENT_str_hash_set_must_replace;
} else if (found && (flags & BCH_HASH_SET_MUST_CREATE)) {
ret = -EEXIST;
} else {
......
......@@ -37,8 +37,12 @@ int bch2_snapshot_tree_invalid(const struct bch_fs *c, struct bkey_s_c k,
int bch2_snapshot_tree_lookup(struct btree_trans *trans, u32 id,
struct bch_snapshot_tree *s)
{
return bch2_bkey_get_val_typed(trans, BTREE_ID_snapshot_trees, POS(0, id),
BTREE_ITER_WITH_UPDATES, snapshot_tree, s);
int ret = bch2_bkey_get_val_typed(trans, BTREE_ID_snapshot_trees, POS(0, id),
BTREE_ITER_WITH_UPDATES, snapshot_tree, s);
if (bch2_err_matches(ret, ENOENT))
ret = -BCH_ERR_ENOENT_snapshot_tree;
return ret;
}
static struct bkey_i_snapshot_tree *
......@@ -284,6 +288,7 @@ static int bch2_snapshot_tree_master_subvol(struct btree_trans *trans,
struct btree_iter iter;
struct bkey_s_c k;
struct bkey_s_c_subvolume s;
bool found = false;
int ret;
for_each_btree_key_norestart(trans, iter, BTREE_ID_subvolumes, POS_MIN,
......@@ -296,14 +301,14 @@ static int bch2_snapshot_tree_master_subvol(struct btree_trans *trans,
continue;
if (!BCH_SUBVOLUME_SNAP(s.v)) {
*subvol_id = s.k->p.offset;
goto found;
found = true;
break;
}
}
ret = ret ?: -ENOENT;
found:
bch2_trans_iter_exit(trans, &iter);
if (bch2_err_matches(ret, ENOENT)) {
if (!ret && !found) {
struct bkey_i_subvolume *s;
*subvol_id = bch2_snapshot_tree_oldest_subvol(c, snapshot_root);
......@@ -1217,7 +1222,7 @@ int bch2_subvolume_get_snapshot(struct btree_trans *trans, u32 subvol,
k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_subvolumes, POS(0, subvol),
BTREE_ITER_CACHED|
BTREE_ITER_WITH_UPDATES);
ret = bkey_err(k) ?: k.k->type == KEY_TYPE_subvolume ? 0 : -ENOENT;
ret = bkey_err(k) ?: k.k->type == KEY_TYPE_subvolume ? 0 : -BCH_ERR_ENOENT_subvolume;
if (likely(!ret))
*snapid = le32_to_cpu(bkey_s_c_to_subvolume(k).v->snapshot);
......@@ -1444,7 +1449,7 @@ int bch2_subvolume_create(struct btree_trans *trans, u64 inode,
BTREE_ITER_CACHED, subvolume);
ret = PTR_ERR_OR_ZERO(src_subvol);
if (unlikely(ret)) {
bch2_fs_inconsistent_on(ret == -ENOENT, c,
bch2_fs_inconsistent_on(bch2_err_matches(ret, ENOENT), c,
"subvolume %u not found", src_subvolid);
goto err;
}
......
......@@ -1833,7 +1833,7 @@ struct bch_dev *bch2_dev_lookup(struct bch_fs *c, const char *name)
for_each_member_device_rcu(ca, c, i, NULL)
if (!strcmp(name, ca->name))
goto found;
ca = ERR_PTR(-ENOENT);
ca = ERR_PTR(-BCH_ERR_ENOENT_dev_not_found);
found:
rcu_read_unlock();
......
......@@ -163,7 +163,7 @@ static int bch2_xattr_get_trans(struct btree_trans *trans, struct bch_inode_info
err2:
bch2_trans_iter_exit(trans, &iter);
err1:
return ret == -ENOENT ? -ENODATA : ret;
return ret < 0 && bch2_err_matches(ret, ENOENT) ? -ENODATA : ret;
}
int bch2_xattr_get(struct bch_fs *c, struct bch_inode_info *inode,
......@@ -229,7 +229,7 @@ int bch2_xattr_set(struct btree_trans *trans, subvol_inum inum,
hash_info, inum, &search);
}
if (ret == -ENOENT)
if (bch2_err_matches(ret, ENOENT))
ret = flags & XATTR_REPLACE ? -ENODATA : 0;
return ret;
......@@ -589,7 +589,7 @@ static int bch2_xattr_bcachefs_set(const struct xattr_handler *handler,
opt_id == Opt_background_target))
bch2_rebalance_add_work(c, inode->v.i_blocks);
return ret;
return bch2_err_class(ret);
}
static const struct xattr_handler bch_xattr_bcachefs_handler = {
......
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