]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
btrfs: add helpers for compression type and level
authorDennis Zhou <dennis@kernel.org>
Mon, 4 Feb 2019 20:19:57 +0000 (15:19 -0500)
committerDavid Sterba <dsterba@suse.com>
Mon, 25 Feb 2019 13:13:30 +0000 (14:13 +0100)
It is very easy to miss places that rely on a certain bitshifting for
decoding the type_level overloading. Add helpers to do this instead.

Cc: Omar Sandoval <osandov@osandov.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Dennis Zhou <dennis@kernel.org>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/compression.c
fs/btrfs/compression.h
fs/btrfs/zlib.c

index 548057630b69e9735d75eb1426869c85c0e521e9..94a0b0a3a301e880f768576f3b9599be2dddc7c6 100644 (file)
@@ -1036,9 +1036,9 @@ int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping,
                         unsigned long *total_in,
                         unsigned long *total_out)
 {
+       int type = btrfs_compress_type(type_level);
        struct list_head *workspace;
        int ret;
-       int type = type_level & 0xF;
 
        workspace = find_workspace(type);
 
index ddda9b80bf2044edc3ae210bb401ce8e728fdbe2..004db0b3111b6d54e94a2d1c65483e362df74363 100644 (file)
@@ -64,6 +64,16 @@ struct compressed_bio {
        u32 sums;
 };
 
+static inline unsigned int btrfs_compress_type(unsigned int type_level)
+{
+       return (type_level & 0xF);
+}
+
+static inline unsigned int btrfs_compress_level(unsigned int type_level)
+{
+       return ((type_level & 0xF0) >> 4);
+}
+
 void __init btrfs_init_compress(void);
 void __cold btrfs_exit_compress(void);
 
index 970ff3e35bb345e598854e5767b8c0981bfbb15c..2bd655c4f8b463e92964ac12e9c1fbe348138fd4 100644 (file)
@@ -393,7 +393,7 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in,
 static void zlib_set_level(struct list_head *ws, unsigned int type)
 {
        struct workspace *workspace = list_entry(ws, struct workspace, list);
-       unsigned level = (type & 0xF0) >> 4;
+       unsigned int level = btrfs_compress_level(type);
 
        if (level > 9)
                level = 9;