btrfs: create structure to encode checksum type and length
authorJohannes Thumshirn <jthumshirn@suse.de>
Fri, 30 Aug 2019 11:36:09 +0000 (13:36 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 9 Sep 2019 12:59:19 +0000 (14:59 +0200)
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 <nborisov@suse.com>
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.c
fs/btrfs/ctree.h

index 88c3b338508dfa14c872b11b5998fbf6d863eddb..98f741c8590558e070f6bfd53b562bb7db4915c7 100644 (file)
@@ -29,6 +29,28 @@ static int balance_node_right(struct btrfs_trans_handle *trans,
 static void del_ptr(struct btrfs_root *root, struct btrfs_path *path,
                    int level, int slot);
 
+static const struct btrfs_csums {
+       u16             size;
+       const char      *name;
+} btrfs_csums[] = {
+       [BTRFS_CSUM_TYPE_CRC32] = { .size = 4, .name = "crc32c" },
+};
+
+int btrfs_super_csum_size(const struct btrfs_super_block *s)
+{
+       u16 t = btrfs_super_csum_type(s);
+       /*
+        * csum type is validated at mount time
+        */
+       return btrfs_csums[t].size;
+}
+
+const char *btrfs_super_csum_name(u16 csum_type)
+{
+       /* csum type is validated at mount time */
+       return btrfs_csums[csum_type].name;
+}
+
 struct btrfs_path *btrfs_alloc_path(void)
 {
        return kmem_cache_zalloc(btrfs_path_cachep, GFP_NOFS);
index 033a0d5d1789d17704b38728814c540cd18b6559..19d669d12ca15226237e698630d7514b65004a88 100644 (file)
@@ -83,10 +83,6 @@ struct btrfs_ref;
  */
 #define BTRFS_LINK_MAX 65535U
 
-/* four bytes for CRC32 */
-static const int btrfs_csum_sizes[] = { 4 };
-static const char *btrfs_csum_names[] = { "crc32c" };
-
 #define BTRFS_EMPTY_DIR_SIZE 0
 
 /* ioprio of readahead is set to idle */
@@ -2167,20 +2163,8 @@ BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64);
 BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
                         uuid_tree_generation, 64);
 
-static inline int btrfs_super_csum_size(const struct btrfs_super_block *s)
-{
-       u16 t = btrfs_super_csum_type(s);
-       /*
-        * csum type is validated at mount time
-        */
-       return btrfs_csum_sizes[t];
-}
-
-static inline const char *btrfs_super_csum_name(u16 csum_type)
-{
-       /* csum type is validated at mount time */
-       return btrfs_csum_names[csum_type];
-}
+int btrfs_super_csum_size(const struct btrfs_super_block *s);
+const char *btrfs_super_csum_name(u16 csum_type);
 
 /*
  * The leaf data grows from end-to-front in the node.