Commit 1972708a authored by Dennis Zhou's avatar Dennis Zhou Committed by David Sterba

btrfs: add helpers for compression type and level

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: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarDennis Zhou <dennis@kernel.org>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 228a73ab
...@@ -1036,9 +1036,9 @@ int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping, ...@@ -1036,9 +1036,9 @@ int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping,
unsigned long *total_in, unsigned long *total_in,
unsigned long *total_out) unsigned long *total_out)
{ {
int type = btrfs_compress_type(type_level);
struct list_head *workspace; struct list_head *workspace;
int ret; int ret;
int type = type_level & 0xF;
workspace = find_workspace(type); workspace = find_workspace(type);
......
...@@ -64,6 +64,16 @@ struct compressed_bio { ...@@ -64,6 +64,16 @@ struct compressed_bio {
u32 sums; 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 __init btrfs_init_compress(void);
void __cold btrfs_exit_compress(void); void __cold btrfs_exit_compress(void);
......
...@@ -393,7 +393,7 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in, ...@@ -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) static void zlib_set_level(struct list_head *ws, unsigned int type)
{ {
struct workspace *workspace = list_entry(ws, struct workspace, list); struct workspace *workspace = list_entry(ws, struct workspace, list);
unsigned level = (type & 0xF0) >> 4; unsigned int level = btrfs_compress_level(type);
if (level > 9) if (level > 9)
level = 9; level = 9;
......
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