diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-05-27 19:59:59 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:10:03 -0400 |
commit | e47a390aa5946e3c5bea7a4a350a88d3bb3ba5b4 (patch) | |
tree | 01ca402a24c057458a13a3f97e4813bc037d2c76 /fs | |
parent | f154c3eb429a340d66a06e8f8d2221d28d25ab45 (diff) | |
download | linux-stable-e47a390aa5946e3c5bea7a4a350a88d3bb3ba5b4.tar.gz linux-stable-e47a390aa5946e3c5bea7a4a350a88d3bb3ba5b4.tar.bz2 linux-stable-e47a390aa5946e3c5bea7a4a350a88d3bb3ba5b4.zip |
bcachefs: Convert -ENOENT to private error codes
As with previous conversions, replace -ENOENT uses with more informative
private error codes.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/bcachefs/acl.c | 6 | ||||
-rw-r--r-- | fs/bcachefs/btree_iter.h | 2 | ||||
-rw-r--r-- | fs/bcachefs/buckets.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/chardev.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/errcode.h | 11 | ||||
-rw-r--r-- | fs/bcachefs/fs-common.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/fs-ioctl.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/fs.c | 6 | ||||
-rw-r--r-- | fs/bcachefs/fsck.c | 24 | ||||
-rw-r--r-- | fs/bcachefs/inode.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/move.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/movinggc.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/quota.c | 4 | ||||
-rw-r--r-- | fs/bcachefs/recovery.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/str_hash.h | 4 | ||||
-rw-r--r-- | fs/bcachefs/subvolume.c | 21 | ||||
-rw-r--r-- | fs/bcachefs/super.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/xattr.c | 6 |
18 files changed, 59 insertions, 43 deletions
diff --git a/fs/bcachefs/acl.c b/fs/bcachefs/acl.c index 2bf58aa89f71..3fe108bc2f08 100644 --- a/fs/bcachefs/acl.c +++ b/fs/bcachefs/acl.c @@ -236,7 +236,7 @@ retry: 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); diff --git a/fs/bcachefs/btree_iter.h b/fs/bcachefs/btree_iter.h index 9a4dbf358fe5..5e5e2a5c715c 100644 --- a/fs/bcachefs/btree_iter.h +++ b/fs/bcachefs/btree_iter.h @@ -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; diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index bd144182c1e1..adf3bd0e4a8f 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -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; diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c index 28854a6c31b9..fb603df099a5 100644 --- a/fs/bcachefs/chardev.c +++ b/fs/bcachefs/chardev.c @@ -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, diff --git a/fs/bcachefs/errcode.h b/fs/bcachefs/errcode.h index c8ac08e5548b..acf9b92f9ab0 100644 --- a/fs/bcachefs/errcode.h +++ b/fs/bcachefs/errcode.h @@ -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) \ diff --git a/fs/bcachefs/fs-common.c b/fs/bcachefs/fs-common.c index 1f2e1fc4f6b2..bb5305441f27 100644 --- a/fs/bcachefs/fs-common.c +++ b/fs/bcachefs/fs-common.c @@ -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; } diff --git a/fs/bcachefs/fs-ioctl.c b/fs/bcachefs/fs-ioctl.c index 269af9393824..dfa1bf73c854 100644 --- a/fs/bcachefs/fs-ioctl.c +++ b/fs/bcachefs/fs-ioctl.c @@ -382,7 +382,7 @@ retry: dir = dst_path.dentry->d_inode; if (IS_DEADDIR(dir)) { - error = -ENOENT; + error = -BCH_ERR_ENOENT_directory_dead; goto err3; } diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c index 99082820e30b..ba7aff6b8a51 100644 --- a/fs/bcachefs/fs.c +++ b/fs/bcachefs/fs.c @@ -105,7 +105,7 @@ retry: 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 @@ retry: 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; diff --git a/fs/bcachefs/fsck.c b/fs/bcachefs/fsck.c index 1b3ee66265c9..dcc55cbd3808 100644 --- a/fs/bcachefs/fsck.c +++ b/fs/bcachefs/fsck.c @@ -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)), diff --git a/fs/bcachefs/inode.c b/fs/bcachefs/inode.c index ddcd7b125f32..64e8d1f8a2fa 100644 --- a/fs/bcachefs/inode.c +++ b/fs/bcachefs/inode.c @@ -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; diff --git a/fs/bcachefs/move.c b/fs/bcachefs/move.c index 2ec30a3fd193..fd629136824b 100644 --- a/fs/bcachefs/move.c +++ b/fs/bcachefs/move.c @@ -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; } diff --git a/fs/bcachefs/movinggc.c b/fs/bcachefs/movinggc.c index 0d96346d5040..6750767276f2 100644 --- a/fs/bcachefs/movinggc.c +++ b/fs/bcachefs/movinggc.c @@ -236,7 +236,7 @@ err: 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)) diff --git a/fs/bcachefs/quota.c b/fs/bcachefs/quota.c index 56ba82cae19d..d20ec9764108 100644 --- a/fs/bcachefs/quota.c +++ b/fs/bcachefs/quota.c @@ -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 = { diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c index af76c029fb6a..e4983d144483 100644 --- a/fs/bcachefs/recovery.c +++ b/fs/bcachefs/recovery.c @@ -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; } diff --git a/fs/bcachefs/str_hash.h b/fs/bcachefs/str_hash.h index 6178ae620ff1..ae21a8cca1b4 100644 --- a/fs/bcachefs/str_hash.h +++ b/fs/bcachefs/str_hash.h @@ -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 @@ found: 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 { diff --git a/fs/bcachefs/subvolume.c b/fs/bcachefs/subvolume.c index 388fa12bbd8b..f07b3e2b3226 100644 --- a/fs/bcachefs/subvolume.c +++ b/fs/bcachefs/subvolume.c @@ -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; } diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index af6cc73d9356..8f0cbd7ada82 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -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(); diff --git a/fs/bcachefs/xattr.c b/fs/bcachefs/xattr.c index 448eb446946b..05c65d94c00f 100644 --- a/fs/bcachefs/xattr.c +++ b/fs/bcachefs/xattr.c @@ -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 @@ err: 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 = { |