]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - fs/btrfs/zlib.c
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux
[mirror_ubuntu-bionic-kernel.git] / fs / btrfs / zlib.c
index c248f9286366fd132735d23cdd8d2411620b5f98..2b52950dc2c68adb03a69b8e10a19108b5ff6acf 100644 (file)
@@ -37,6 +37,7 @@ struct workspace {
        z_stream strm;
        char *buf;
        struct list_head list;
+       int level;
 };
 
 static void zlib_free_workspace(struct list_head *ws)
@@ -96,7 +97,7 @@ static int zlib_compress_pages(struct list_head *ws,
        *total_out = 0;
        *total_in = 0;
 
-       if (Z_OK != zlib_deflateInit(&workspace->strm, 3)) {
+       if (Z_OK != zlib_deflateInit(&workspace->strm, workspace->level)) {
                pr_warn("BTRFS: deflateInit failed\n");
                ret = -EIO;
                goto out;
@@ -402,10 +403,22 @@ next:
        return ret;
 }
 
+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;
+
+       if (level > 9)
+               level = 9;
+
+       workspace->level = level > 0 ? level : 3;
+}
+
 const struct btrfs_compress_op btrfs_zlib_compress = {
        .alloc_workspace        = zlib_alloc_workspace,
        .free_workspace         = zlib_free_workspace,
        .compress_pages         = zlib_compress_pages,
        .decompress_bio         = zlib_decompress_bio,
        .decompress             = zlib_decompress,
+       .set_level              = zlib_set_level,
 };