Skip to content

Commit af024ed

Browse files
Johannes Thumshirnkdave
authored andcommitted
btrfs: create structure to encode checksum type and length
Create a structure to encode the type and length for the known on-disk checksums. This makes it easier to add new checksums later. The structure and helpers are moved from ctree.h so they don't occupy space in all headers including ctree.h. This save some space in the final object. Reviewed-by: Nikolay Borisov <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent e35b79a commit af024ed

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

fs/btrfs/ctree.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ static int balance_node_right(struct btrfs_trans_handle *trans,
2929
static void del_ptr(struct btrfs_root *root, struct btrfs_path *path,
3030
int level, int slot);
3131

32+
static const struct btrfs_csums {
33+
u16 size;
34+
const char *name;
35+
} btrfs_csums[] = {
36+
[BTRFS_CSUM_TYPE_CRC32] = { .size = 4, .name = "crc32c" },
37+
};
38+
39+
int btrfs_super_csum_size(const struct btrfs_super_block *s)
40+
{
41+
u16 t = btrfs_super_csum_type(s);
42+
/*
43+
* csum type is validated at mount time
44+
*/
45+
return btrfs_csums[t].size;
46+
}
47+
48+
const char *btrfs_super_csum_name(u16 csum_type)
49+
{
50+
/* csum type is validated at mount time */
51+
return btrfs_csums[csum_type].name;
52+
}
53+
3254
struct btrfs_path *btrfs_alloc_path(void)
3355
{
3456
return kmem_cache_zalloc(btrfs_path_cachep, GFP_NOFS);

fs/btrfs/ctree.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ struct btrfs_ref;
8383
*/
8484
#define BTRFS_LINK_MAX 65535U
8585

86-
/* four bytes for CRC32 */
87-
static const int btrfs_csum_sizes[] = { 4 };
88-
static const char *btrfs_csum_names[] = { "crc32c" };
89-
9086
#define BTRFS_EMPTY_DIR_SIZE 0
9187

9288
/* ioprio of readahead is set to idle */
@@ -2167,20 +2163,8 @@ BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64);
21672163
BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
21682164
uuid_tree_generation, 64);
21692165

2170-
static inline int btrfs_super_csum_size(const struct btrfs_super_block *s)
2171-
{
2172-
u16 t = btrfs_super_csum_type(s);
2173-
/*
2174-
* csum type is validated at mount time
2175-
*/
2176-
return btrfs_csum_sizes[t];
2177-
}
2178-
2179-
static inline const char *btrfs_super_csum_name(u16 csum_type)
2180-
{
2181-
/* csum type is validated at mount time */
2182-
return btrfs_csum_names[csum_type];
2183-
}
2166+
int btrfs_super_csum_size(const struct btrfs_super_block *s);
2167+
const char *btrfs_super_csum_name(u16 csum_type);
21842168

21852169
/*
21862170
* The leaf data grows from end-to-front in the node.

0 commit comments

Comments
 (0)