btrfs: compression: inline get_workspace
authorDavid Sterba <dsterba@suse.com>
Fri, 4 Oct 2019 00:36:16 +0000 (02:36 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 18 Nov 2019 11:46:58 +0000 (12:46 +0100)
Majority of the callbacks is trivial, we don't gain anything by the
indirection, so replace them by a switch function.

ZLIB needs to adjust level in the callback and ZSTD workspace management
is complex, the rest is call to the helper.

Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/compression.c
fs/btrfs/compression.h
fs/btrfs/lzo.c
fs/btrfs/zlib.c
fs/btrfs/zstd.c

index f707db4a9a53a3389e575aa964b94ff42c1d91a9..de9b06574f4267abd9a104276c05913d4b73bbdc 100644 (file)
@@ -50,7 +50,6 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in,
                size_t destlen);
 struct list_head *lzo_alloc_workspace(unsigned int level);
 void lzo_free_workspace(struct list_head *ws);
-struct list_head *lzo_get_workspace(unsigned int level);
 void lzo_put_workspace(struct list_head *ws);
 
 int zstd_compress_pages(struct list_head *ws, struct address_space *mapping,
@@ -874,11 +873,6 @@ struct heuristic_ws {
 
 static struct workspace_manager heuristic_wsm;
 
-static struct list_head *heuristic_get_workspace(unsigned int level)
-{
-       return btrfs_get_workspace(&heuristic_wsm, level);
-}
-
 static void heuristic_put_workspace(struct list_head *ws)
 {
        btrfs_put_workspace(&heuristic_wsm, ws);
@@ -925,7 +919,6 @@ fail:
 
 const struct btrfs_compress_op btrfs_heuristic_compress = {
        .workspace_manager = &heuristic_wsm,
-       .get_workspace = heuristic_get_workspace,
        .put_workspace = heuristic_put_workspace,
        .alloc_workspace = alloc_heuristic_ws,
        .free_workspace = free_heuristic_ws,
@@ -1067,7 +1060,21 @@ again:
 
 static struct list_head *get_workspace(int type, int level)
 {
-       return btrfs_compress_op[type]->get_workspace(level);
+       struct workspace_manager *wsm;
+
+       wsm = btrfs_compress_op[type]->workspace_manager;
+       switch (type) {
+       case BTRFS_COMPRESS_NONE: return btrfs_get_workspace(wsm, level);
+       case BTRFS_COMPRESS_ZLIB: return zlib_get_workspace(level);
+       case BTRFS_COMPRESS_LZO:  return btrfs_get_workspace(wsm, level);
+       case BTRFS_COMPRESS_ZSTD: return zstd_get_workspace(level);
+       default:
+               /*
+                * This can't happen, the type is validated several times
+                * before we get here.
+                */
+               BUG();
+       }
 }
 
 /*
index cf667e599b70ce5ddd4d923bfa36d9c988cd3411..df7274c1a5d8914cf9bdfdbc332ef14b21bd6343 100644 (file)
@@ -125,8 +125,6 @@ struct list_head *btrfs_get_workspace(struct workspace_manager *wsm,
 void btrfs_put_workspace(struct workspace_manager *wsm, struct list_head *ws);
 
 struct btrfs_compress_op {
-       struct list_head *(*get_workspace)(unsigned int level);
-
        void (*put_workspace)(struct list_head *ws);
 
        struct list_head *(*alloc_workspace)(unsigned int level);
index 18018619c019dc06a84a70b27e60f90e2e4ef6bf..821e5c137971cd4056dd2e6122144bc829b7d3d5 100644 (file)
@@ -63,11 +63,6 @@ struct workspace {
 
 static struct workspace_manager wsm;
 
-struct list_head *lzo_get_workspace(unsigned int level)
-{
-       return btrfs_get_workspace(&wsm, level);
-}
-
 void lzo_put_workspace(struct list_head *ws)
 {
        btrfs_put_workspace(&wsm, ws);
@@ -494,7 +489,6 @@ out:
 
 const struct btrfs_compress_op btrfs_lzo_compress = {
        .workspace_manager      = &wsm,
-       .get_workspace          = lzo_get_workspace,
        .put_workspace          = lzo_put_workspace,
        .alloc_workspace        = lzo_alloc_workspace,
        .free_workspace         = lzo_free_workspace,
index f2a56e999e5f9407212253cf60d752dea5f01ae1..7caa468efe94e48a83c77dc7c82a392031b1940e 100644 (file)
@@ -405,7 +405,6 @@ next:
 
 const struct btrfs_compress_op btrfs_zlib_compress = {
        .workspace_manager      = &wsm,
-       .get_workspace          = zlib_get_workspace,
        .put_workspace          = zlib_put_workspace,
        .alloc_workspace        = zlib_alloc_workspace,
        .free_workspace         = zlib_free_workspace,
index 2caf08e06e2f85c2d87105f3e52afe27784a6ebb..c9fe0e2bd1079cd5a1d78b1b3b85c5eff52a0c00 100644 (file)
@@ -708,7 +708,6 @@ finish:
 const struct btrfs_compress_op btrfs_zstd_compress = {
        /* ZSTD uses own workspace manager */
        .workspace_manager = NULL,
-       .get_workspace = zstd_get_workspace,
        .put_workspace = zstd_put_workspace,
        .alloc_workspace = zstd_alloc_workspace,
        .free_workspace = zstd_free_workspace,