Commit 5927310d authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch_str_hash_flags_t

Create a separate enum for str_hash flags - instead of abusing the
btree_insert_flags enum - and create a __bitwise typedef for sparse
typechecking.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent aa62aabb
...@@ -28,8 +28,6 @@ enum btree_insert_flags { ...@@ -28,8 +28,6 @@ enum btree_insert_flags {
__BTREE_INSERT_LAZY_RW, __BTREE_INSERT_LAZY_RW,
__BTREE_INSERT_JOURNAL_REPLAY, __BTREE_INSERT_JOURNAL_REPLAY,
__BTREE_INSERT_JOURNAL_RECLAIM, __BTREE_INSERT_JOURNAL_RECLAIM,
__BCH_HASH_SET_MUST_CREATE,
__BCH_HASH_SET_MUST_REPLACE,
}; };
/* Don't check for -ENOSPC: */ /* Don't check for -ENOSPC: */
...@@ -44,9 +42,6 @@ enum btree_insert_flags { ...@@ -44,9 +42,6 @@ enum btree_insert_flags {
/* Insert is being called from journal reclaim path: */ /* Insert is being called from journal reclaim path: */
#define BTREE_INSERT_JOURNAL_RECLAIM BIT(__BTREE_INSERT_JOURNAL_RECLAIM) #define BTREE_INSERT_JOURNAL_RECLAIM BIT(__BTREE_INSERT_JOURNAL_RECLAIM)
#define BCH_HASH_SET_MUST_CREATE BIT(__BCH_HASH_SET_MUST_CREATE)
#define BCH_HASH_SET_MUST_REPLACE BIT(__BCH_HASH_SET_MUST_REPLACE)
int bch2_btree_delete_extent_at(struct btree_trans *, struct btree_iter *, int bch2_btree_delete_extent_at(struct btree_trans *, struct btree_iter *,
unsigned, unsigned); unsigned, unsigned);
int bch2_btree_delete_at(struct btree_trans *, struct btree_iter *, unsigned); int bch2_btree_delete_at(struct btree_trans *, struct btree_iter *, unsigned);
......
...@@ -201,7 +201,8 @@ static struct bkey_i_dirent *dirent_create_key(struct btree_trans *trans, ...@@ -201,7 +201,8 @@ static struct bkey_i_dirent *dirent_create_key(struct btree_trans *trans,
int bch2_dirent_create(struct btree_trans *trans, subvol_inum dir, int bch2_dirent_create(struct btree_trans *trans, subvol_inum dir,
const struct bch_hash_info *hash_info, const struct bch_hash_info *hash_info,
u8 type, const struct qstr *name, u64 dst_inum, u8 type, const struct qstr *name, u64 dst_inum,
u64 *dir_offset, int flags) u64 *dir_offset,
bch_str_hash_flags_t str_hash_flags)
{ {
struct bkey_i_dirent *dirent; struct bkey_i_dirent *dirent;
int ret; int ret;
...@@ -212,7 +213,7 @@ int bch2_dirent_create(struct btree_trans *trans, subvol_inum dir, ...@@ -212,7 +213,7 @@ int bch2_dirent_create(struct btree_trans *trans, subvol_inum dir,
return ret; return ret;
ret = bch2_hash_set(trans, bch2_dirent_hash_desc, hash_info, ret = bch2_hash_set(trans, bch2_dirent_hash_desc, hash_info,
dir, &dirent->k_i, flags); dir, &dirent->k_i, str_hash_flags);
*dir_offset = dirent->k.p.offset; *dir_offset = dirent->k.p.offset;
return ret; return ret;
......
...@@ -37,7 +37,8 @@ int bch2_dirent_read_target(struct btree_trans *, subvol_inum, ...@@ -37,7 +37,8 @@ int bch2_dirent_read_target(struct btree_trans *, subvol_inum,
int bch2_dirent_create(struct btree_trans *, subvol_inum, int bch2_dirent_create(struct btree_trans *, subvol_inum,
const struct bch_hash_info *, u8, const struct bch_hash_info *, u8,
const struct qstr *, u64, u64 *, int); const struct qstr *, u64, u64 *,
bch_str_hash_flags_t);
static inline unsigned vfs_d_type(unsigned type) static inline unsigned vfs_d_type(unsigned type)
{ {
......
...@@ -15,6 +15,16 @@ ...@@ -15,6 +15,16 @@
#include <crypto/hash.h> #include <crypto/hash.h>
#include <crypto/sha2.h> #include <crypto/sha2.h>
typedef unsigned __bitwise bch_str_hash_flags_t;
enum bch_str_hash_flags {
__BCH_HASH_SET_MUST_CREATE,
__BCH_HASH_SET_MUST_REPLACE,
};
#define BCH_HASH_SET_MUST_CREATE (__force bch_str_hash_flags_t) BIT(__BCH_HASH_SET_MUST_CREATE)
#define BCH_HASH_SET_MUST_REPLACE (__force bch_str_hash_flags_t) BIT(__BCH_HASH_SET_MUST_REPLACE)
static inline enum bch_str_hash_type static inline enum bch_str_hash_type
bch2_str_hash_opt_to_type(struct bch_fs *c, enum bch_str_hash_opts opt) bch2_str_hash_opt_to_type(struct bch_fs *c, enum bch_str_hash_opts opt)
{ {
...@@ -246,7 +256,7 @@ int bch2_hash_set_snapshot(struct btree_trans *trans, ...@@ -246,7 +256,7 @@ int bch2_hash_set_snapshot(struct btree_trans *trans,
const struct bch_hash_info *info, const struct bch_hash_info *info,
subvol_inum inum, u32 snapshot, subvol_inum inum, u32 snapshot,
struct bkey_i *insert, struct bkey_i *insert,
int flags, bch_str_hash_flags_t str_hash_flags,
int update_flags) int update_flags)
{ {
struct btree_iter iter, slot = { NULL }; struct btree_iter iter, slot = { NULL };
...@@ -269,7 +279,7 @@ int bch2_hash_set_snapshot(struct btree_trans *trans, ...@@ -269,7 +279,7 @@ int bch2_hash_set_snapshot(struct btree_trans *trans,
} }
if (!slot.path && if (!slot.path &&
!(flags & BCH_HASH_SET_MUST_REPLACE)) !(str_hash_flags & BCH_HASH_SET_MUST_REPLACE))
bch2_trans_copy_iter(&slot, &iter); bch2_trans_copy_iter(&slot, &iter);
if (k.k->type != KEY_TYPE_hash_whiteout) if (k.k->type != KEY_TYPE_hash_whiteout)
...@@ -287,16 +297,16 @@ int bch2_hash_set_snapshot(struct btree_trans *trans, ...@@ -287,16 +297,16 @@ int bch2_hash_set_snapshot(struct btree_trans *trans,
found = true; found = true;
not_found: not_found:
if (!found && (flags & BCH_HASH_SET_MUST_REPLACE)) { if (!found && (str_hash_flags & BCH_HASH_SET_MUST_REPLACE)) {
ret = -BCH_ERR_ENOENT_str_hash_set_must_replace; ret = -BCH_ERR_ENOENT_str_hash_set_must_replace;
} else if (found && (flags & BCH_HASH_SET_MUST_CREATE)) { } else if (found && (str_hash_flags & BCH_HASH_SET_MUST_CREATE)) {
ret = -EEXIST; ret = -EEXIST;
} else { } else {
if (!found && slot.path) if (!found && slot.path)
swap(iter, slot); swap(iter, slot);
insert->k.p = iter.pos; insert->k.p = iter.pos;
ret = bch2_trans_update(trans, &iter, insert, 0); ret = bch2_trans_update(trans, &iter, insert, update_flags);
} }
goto out; goto out;
...@@ -307,7 +317,8 @@ int bch2_hash_set(struct btree_trans *trans, ...@@ -307,7 +317,8 @@ int bch2_hash_set(struct btree_trans *trans,
const struct bch_hash_desc desc, const struct bch_hash_desc desc,
const struct bch_hash_info *info, const struct bch_hash_info *info,
subvol_inum inum, subvol_inum inum,
struct bkey_i *insert, int flags) struct bkey_i *insert,
bch_str_hash_flags_t str_hash_flags)
{ {
u32 snapshot; u32 snapshot;
int ret; int ret;
...@@ -319,7 +330,7 @@ int bch2_hash_set(struct btree_trans *trans, ...@@ -319,7 +330,7 @@ int bch2_hash_set(struct btree_trans *trans,
insert->k.p.inode = inum.inum; insert->k.p.inode = inum.inum;
return bch2_hash_set_snapshot(trans, desc, info, inum, return bch2_hash_set_snapshot(trans, desc, info, inum,
snapshot, insert, flags, 0); snapshot, insert, str_hash_flags, 0);
} }
static __always_inline static __always_inline
......
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