btrfs: plumb level through the compression interface
[sfrench/cifs-2.6.git] / fs / btrfs / zlib.c
index 970ff3e35bb345e598854e5767b8c0981bfbb15c..fc883a14ecbfed02a907e0926f2b326be20aa5b2 100644 (file)
@@ -27,6 +27,28 @@ struct workspace {
        int level;
 };
 
+static struct workspace_manager wsm;
+
+static void zlib_init_workspace_manager(void)
+{
+       btrfs_init_workspace_manager(&wsm, &btrfs_zlib_compress);
+}
+
+static void zlib_cleanup_workspace_manager(void)
+{
+       btrfs_cleanup_workspace_manager(&wsm);
+}
+
+static struct list_head *zlib_get_workspace(unsigned int level)
+{
+       return btrfs_get_workspace(&wsm, level);
+}
+
+static void zlib_put_workspace(struct list_head *ws)
+{
+       btrfs_put_workspace(&wsm, ws);
+}
+
 static void zlib_free_workspace(struct list_head *ws)
 {
        struct workspace *workspace = list_entry(ws, struct workspace, list);
@@ -36,7 +58,7 @@ static void zlib_free_workspace(struct list_head *ws)
        kfree(workspace);
 }
 
-static struct list_head *zlib_alloc_workspace(void)
+static struct list_head *zlib_alloc_workspace(unsigned int level)
 {
        struct workspace *workspace;
        int workspacesize;
@@ -48,6 +70,7 @@ static struct list_head *zlib_alloc_workspace(void)
        workspacesize = max(zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL),
                        zlib_inflate_workspacesize());
        workspace->strm.workspace = kvmalloc(workspacesize, GFP_KERNEL);
+       workspace->level = level;
        workspace->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
        if (!workspace->strm.workspace || !workspace->buf)
                goto fail;
@@ -393,7 +416,7 @@ next:
 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;
@@ -402,6 +425,10 @@ static void zlib_set_level(struct list_head *ws, unsigned int type)
 }
 
 const struct btrfs_compress_op btrfs_zlib_compress = {
+       .init_workspace_manager = zlib_init_workspace_manager,
+       .cleanup_workspace_manager = zlib_cleanup_workspace_manager,
+       .get_workspace          = zlib_get_workspace,
+       .put_workspace          = zlib_put_workspace,
        .alloc_workspace        = zlib_alloc_workspace,
        .free_workspace         = zlib_free_workspace,
        .compress_pages         = zlib_compress_pages,