bcachefs: Converting to typed bkeys is now allowed for err, null ptrs
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 30 Apr 2023 17:02:05 +0000 (13:02 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:10:00 +0000 (17:10 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/bkey.h
fs/bcachefs/btree_iter.h
fs/bcachefs/fsck.c

index 29f44d0060d859a53a767bd8b2c0b35461fe1da6..e81fb3e00c602dfca2e544ac85de7b4584c5b92d 100644 (file)
@@ -619,20 +619,20 @@ struct bkey_s_##name {                                                    \
                                                                        \
 static inline struct bkey_i_##name *bkey_i_to_##name(struct bkey_i *k) \
 {                                                                      \
-       EBUG_ON(k->k.type != KEY_TYPE_##name);                          \
+       EBUG_ON(!IS_ERR_OR_NULL(k) && k->k.type != KEY_TYPE_##name);    \
        return container_of(&k->k, struct bkey_i_##name, k);            \
 }                                                                      \
                                                                        \
 static inline const struct bkey_i_##name *                             \
 bkey_i_to_##name##_c(const struct bkey_i *k)                           \
 {                                                                      \
-       EBUG_ON(k->k.type != KEY_TYPE_##name);                          \
+       EBUG_ON(!IS_ERR_OR_NULL(k) && k->k.type != KEY_TYPE_##name);    \
        return container_of(&k->k, struct bkey_i_##name, k);            \
 }                                                                      \
                                                                        \
 static inline struct bkey_s_##name bkey_s_to_##name(struct bkey_s k)   \
 {                                                                      \
-       EBUG_ON(k.k->type != KEY_TYPE_##name);                          \
+       EBUG_ON(!IS_ERR_OR_NULL(k.k) && k.k->type != KEY_TYPE_##name);  \
        return (struct bkey_s_##name) {                                 \
                .k = k.k,                                               \
                .v = container_of(k.v, struct bch_##name, v),           \
@@ -641,7 +641,7 @@ static inline struct bkey_s_##name bkey_s_to_##name(struct bkey_s k)        \
                                                                        \
 static inline struct bkey_s_c_##name bkey_s_c_to_##name(struct bkey_s_c k)\
 {                                                                      \
-       EBUG_ON(k.k->type != KEY_TYPE_##name);                          \
+       EBUG_ON(!IS_ERR_OR_NULL(k.k) && k.k->type != KEY_TYPE_##name);  \
        return (struct bkey_s_c_##name) {                               \
                .k = k.k,                                               \
                .v = container_of(k.v, struct bch_##name, v),           \
@@ -667,7 +667,7 @@ name##_i_to_s_c(const struct bkey_i_##name *k)                              \
                                                                        \
 static inline struct bkey_s_##name bkey_i_to_s_##name(struct bkey_i *k)        \
 {                                                                      \
-       EBUG_ON(k->k.type != KEY_TYPE_##name);                          \
+       EBUG_ON(!IS_ERR_OR_NULL(k) && k->k.type != KEY_TYPE_##name);    \
        return (struct bkey_s_##name) {                                 \
                .k = &k->k,                                             \
                .v = container_of(&k->v, struct bch_##name, v),         \
@@ -677,7 +677,7 @@ static inline struct bkey_s_##name bkey_i_to_s_##name(struct bkey_i *k)     \
 static inline struct bkey_s_c_##name                                   \
 bkey_i_to_s_c_##name(const struct bkey_i *k)                           \
 {                                                                      \
-       EBUG_ON(k->k.type != KEY_TYPE_##name);                          \
+       EBUG_ON(!IS_ERR_OR_NULL(k) && k->k.type != KEY_TYPE_##name);    \
        return (struct bkey_s_c_##name) {                               \
                .k = &k->k,                                             \
                .v = container_of(&k->v, struct bch_##name, v),         \
index c3682332e653a818835d55a91453f65c0644305d..4790472a3d0d2deac848c96931143daac2332028 100644 (file)
@@ -6,6 +6,13 @@
 #include "btree_types.h"
 #include "trace.h"
 
+static inline int __bkey_err(const struct bkey *k)
+{
+       return PTR_ERR_OR_ZERO(k);
+}
+
+#define bkey_err(_k)   __bkey_err((_k).k)
+
 static inline void __btree_path_get(struct btree_path *path, bool intent)
 {
        path->ref++;
@@ -539,11 +546,6 @@ u32 bch2_trans_begin(struct btree_trans *);
        __for_each_btree_node(_trans, _iter, _btree_id, _start,         \
                              0, 0, _flags, _b, _ret)
 
-static inline int bkey_err(struct bkey_s_c k)
-{
-       return PTR_ERR_OR_ZERO(k.k);
-}
-
 static inline struct bkey_s_c bch2_btree_iter_peek_prev_type(struct btree_iter *iter,
                                                             unsigned flags)
 {
index 4e71005777348667bd2875031b07f279e3a618eb..eda1f030f784c679b8f6ccb6f1316843b03737a5 100644 (file)
@@ -1122,7 +1122,7 @@ static int inode_backpointer_exists(struct btree_trans *trans,
 
        d = dirent_get_by_pos(trans, &iter,
                        SPOS(inode->bi_dir, inode->bi_dir_offset, snapshot));
-       ret = bkey_err(d.s_c);
+       ret = bkey_err(d);
        if (ret)
                return ret == -ENOENT ? 0 : ret;