Skip to content

Commit 6a0d127

Browse files
committed
btrfs: compression: inline get_workspace
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>
1 parent d20f395 commit 6a0d127

5 files changed

Lines changed: 15 additions & 18 deletions

File tree

‎fs/btrfs/compression.c‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in,
5050
size_t destlen);
5151
struct list_head *lzo_alloc_workspace(unsigned int level);
5252
void lzo_free_workspace(struct list_head *ws);
53-
struct list_head *lzo_get_workspace(unsigned int level);
5453
void lzo_put_workspace(struct list_head *ws);
5554

5655
int zstd_compress_pages(struct list_head *ws, struct address_space *mapping,
@@ -874,11 +873,6 @@ struct heuristic_ws {
874873

875874
static struct workspace_manager heuristic_wsm;
876875

877-
static struct list_head *heuristic_get_workspace(unsigned int level)
878-
{
879-
return btrfs_get_workspace(&heuristic_wsm, level);
880-
}
881-
882876
static void heuristic_put_workspace(struct list_head *ws)
883877
{
884878
btrfs_put_workspace(&heuristic_wsm, ws);
@@ -925,7 +919,6 @@ static struct list_head *alloc_heuristic_ws(unsigned int level)
925919

926920
const struct btrfs_compress_op btrfs_heuristic_compress = {
927921
.workspace_manager = &heuristic_wsm,
928-
.get_workspace = heuristic_get_workspace,
929922
.put_workspace = heuristic_put_workspace,
930923
.alloc_workspace = alloc_heuristic_ws,
931924
.free_workspace = free_heuristic_ws,
@@ -1067,7 +1060,21 @@ struct list_head *btrfs_get_workspace(struct workspace_manager *wsm,
10671060

10681061
static struct list_head *get_workspace(int type, int level)
10691062
{
1070-
return btrfs_compress_op[type]->get_workspace(level);
1063+
struct workspace_manager *wsm;
1064+
1065+
wsm = btrfs_compress_op[type]->workspace_manager;
1066+
switch (type) {
1067+
case BTRFS_COMPRESS_NONE: return btrfs_get_workspace(wsm, level);
1068+
case BTRFS_COMPRESS_ZLIB: return zlib_get_workspace(level);
1069+
case BTRFS_COMPRESS_LZO: return btrfs_get_workspace(wsm, level);
1070+
case BTRFS_COMPRESS_ZSTD: return zstd_get_workspace(level);
1071+
default:
1072+
/*
1073+
* This can't happen, the type is validated several times
1074+
* before we get here.
1075+
*/
1076+
BUG();
1077+
}
10711078
}
10721079

10731080
/*

‎fs/btrfs/compression.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ struct list_head *btrfs_get_workspace(struct workspace_manager *wsm,
125125
void btrfs_put_workspace(struct workspace_manager *wsm, struct list_head *ws);
126126

127127
struct btrfs_compress_op {
128-
struct list_head *(*get_workspace)(unsigned int level);
129-
130128
void (*put_workspace)(struct list_head *ws);
131129

132130
struct list_head *(*alloc_workspace)(unsigned int level);

‎fs/btrfs/lzo.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ struct workspace {
6363

6464
static struct workspace_manager wsm;
6565

66-
struct list_head *lzo_get_workspace(unsigned int level)
67-
{
68-
return btrfs_get_workspace(&wsm, level);
69-
}
70-
7166
void lzo_put_workspace(struct list_head *ws)
7267
{
7368
btrfs_put_workspace(&wsm, ws);
@@ -494,7 +489,6 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in,
494489

495490
const struct btrfs_compress_op btrfs_lzo_compress = {
496491
.workspace_manager = &wsm,
497-
.get_workspace = lzo_get_workspace,
498492
.put_workspace = lzo_put_workspace,
499493
.alloc_workspace = lzo_alloc_workspace,
500494
.free_workspace = lzo_free_workspace,

‎fs/btrfs/zlib.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ int zlib_decompress(struct list_head *ws, unsigned char *data_in,
405405

406406
const struct btrfs_compress_op btrfs_zlib_compress = {
407407
.workspace_manager = &wsm,
408-
.get_workspace = zlib_get_workspace,
409408
.put_workspace = zlib_put_workspace,
410409
.alloc_workspace = zlib_alloc_workspace,
411410
.free_workspace = zlib_free_workspace,

‎fs/btrfs/zstd.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ int zstd_decompress(struct list_head *ws, unsigned char *data_in,
708708
const struct btrfs_compress_op btrfs_zstd_compress = {
709709
/* ZSTD uses own workspace manager */
710710
.workspace_manager = NULL,
711-
.get_workspace = zstd_get_workspace,
712711
.put_workspace = zstd_put_workspace,
713712
.alloc_workspace = zstd_alloc_workspace,
714713
.free_workspace = zstd_free_workspace,

0 commit comments

Comments
 (0)