summaryrefslogtreecommitdiff
path: root/fs/btrfs/compression.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2019-08-09 16:49:06 +0200
committerDavid Sterba <dsterba@suse.com>2019-09-09 14:59:11 +0200
commitb0c1fe1eaf5eea10e8d577545298b6d5f9f7ff38 (patch)
tree8d487a078a47357a06992bc8008293fb2bd35c26 /fs/btrfs/compression.c
parente18333a7cb97d838c09802092fcecd3269363ecb (diff)
downloadlwn-b0c1fe1eaf5eea10e8d577545298b6d5f9f7ff38.tar.gz
lwn-b0c1fe1eaf5eea10e8d577545298b6d5f9f7ff38.zip
btrfs: compression: replace set_level callbacks by a common helper
The set_level callbacks do not do anything special and can be replaced by a helper that uses the levels defined in the tables. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/compression.c')
-rw-r--r--fs/btrfs/compression.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 60c47b417a4b..fe7a8b5ff96c 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -1039,7 +1039,7 @@ int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping,
struct list_head *workspace;
int ret;
- level = btrfs_compress_op[type]->set_level(level);
+ level = btrfs_compress_set_level(type, level);
workspace = get_workspace(type, level);
ret = btrfs_compress_op[type]->compress_pages(workspace, mapping,
start, pages,
@@ -1611,7 +1611,23 @@ unsigned int btrfs_compress_str2level(unsigned int type, const char *str)
level = 0;
}
- level = btrfs_compress_op[type]->set_level(level);
+ level = btrfs_compress_set_level(type, level);
+
+ return level;
+}
+
+/*
+ * Adjust @level according to the limits of the compression algorithm or
+ * fallback to default
+ */
+unsigned int btrfs_compress_set_level(int type, unsigned level)
+{
+ const struct btrfs_compress_op *ops = btrfs_compress_op[type];
+
+ if (level == 0)
+ level = ops->default_level;
+ else
+ level = min(level, ops->max_level);
return level;
}