Compression level API cleanups
Subsystems (2)
David Sterba
maintainerv2 cover Compression level API cleanups
Remove the callback indirection.
v2:
* switch to unsigned int and use min()
David Sterba (2):
btrfs: define compression levels statically
btrfs: compression: replace set_level callbacks by a common helper
fs/btrfs/compression.c | 20 ++++++++++++++++++-- fs/btrfs/compression.h | 11 +++++------ fs/btrfs/lzo.c | 8 ++------ fs/btrfs/zlib.c | 11 ++--------- fs/btrfs/zstd.c | 11 ++--------- 5 files changed, 29 insertions(+), 32 deletions(-)
Signature · 1 line
2.22.0
David Sterba
maintainerPATCH v2 1/2 btrfs: define compression levels statically
The maximum and default levels do not change and can be defined directly. The set_level callback was a temporary solution and will be removed.
--- fs/btrfs/compression.h | 4 ++++ fs/btrfs/lzo.c | 2 ++ fs/btrfs/zlib.c | 2 ++ fs/btrfs/zstd.c | 2 ++ 4 files changed, 10 insertions(+)
fs/btrfs/compression.h +4 -0
@@ -162,6 +162,10 @@ struct btrfs_compress_op {* if the level is out of bounds or the default if 0 is passed in. */ unsigned int (*set_level)(unsigned int level); + +/* Maximum level supported by the compression algorithm */ +unsigned int max_level; +unsigned int default_level; };/* The heuristic workspaces are managed via the 0th workspace manager */
fs/btrfs/lzo.c +2 -0
@@ -523,4 +523,6 @@ const struct btrfs_compress_op btrfs_lzo_compress = { .decompress_bio = lzo_decompress_bio, .decompress = lzo_decompress, .set_level = lzo_set_level, + .max_level = 1, + .default_level = 1, };
fs/btrfs/zlib.c +2 -0
@@ -437,4 +437,6 @@ const struct btrfs_compress_op btrfs_zlib_compress = { .decompress_bio = zlib_decompress_bio, .decompress = zlib_decompress, .set_level = zlib_set_level, + .max_level = 9, + .default_level = BTRFS_ZLIB_DEFAULT_LEVEL, };
fs/btrfs/zstd.c +2 -0
@@ -729,4 +729,6 @@ const struct btrfs_compress_op btrfs_zstd_compress = { .decompress_bio = zstd_decompress_bio, .decompress = zstd_decompress, .set_level = zstd_set_level, + .max_level = ZSTD_BTRFS_MAX_LEVEL, + .default_level = ZSTD_BTRFS_DEFAULT_LEVEL, };
Signature · 1 line
2.22.0
Re: [PATCH v2 1/2] btrfs: define compression levels statically
Quoted 5 lines · David Sterba
The maximum and default levels do not change and can be defined directly. The
set_levelcallback was a temporary solution and will be removed.Signed-off-by David Sterba <[email protected]>
David Sterba
maintainerPATCH v2 2/2 btrfs: compression: replace set_level callbacks by a common helper
In reply to David SterbaThe set_level callbacks do not do anything special and can be replaced by a helper that uses the levels defined in the tables.
--- fs/btrfs/compression.c | 20 ++++++++++++++++++-- fs/btrfs/compression.h | 9 ++------- fs/btrfs/lzo.c | 6 ------ fs/btrfs/zlib.c | 9 --------- fs/btrfs/zstd.c | 9 --------- 5 files changed, 20 insertions(+), 33 deletions(-)
fs/btrfs/compression.c +18 -2
@@ -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_get_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; }
fs/btrfs/compression.h +2 -7
@@ -156,13 +156,6 @@ struct btrfs_compress_op {unsigned long start_byte, size_t srclen, size_t destlen); -/* -* This bounds the level set by the user to be within range of a -* particular compression type. It returns the level that will be used -* if the level is out of bounds or the default if 0 is passed in. -*/ -unsigned int (*set_level)(unsigned int level); -/* Maximum level supported by the compression algorithm */ unsigned int max_level;unsigned int default_level;
@@ -179,6 +172,8 @@ extern const struct btrfs_compress_op btrfs_zstd_compress;const char *btrfs_compress_type2str (enum btrfs_compression_type type);bool btrfs_compress_is_valid_type (const char *str,size_t len); +unsigned int btrfs_compress_set_level (int type,unsigned level); +int btrfs_compress_heuristic (struct inode *inode,u64 start,u64 end);#endif
fs/btrfs/lzo.c +0 -6
@@ -507,11 +507,6 @@ static int lzo_decompress(struct list_head *ws, unsigned char *data_in,return ret; } -static unsigned int lzo_set_level (unsigned int level) -{ -return 0 ; -} -const struct btrfs_compress_op btrfs_lzo_compress = { .init_workspace_manager = lzo_init_workspace_manager, .cleanup_workspace_manager = lzo_cleanup_workspace_manager,
@@ -522,7 +517,6 @@ const struct btrfs_compress_op btrfs_lzo_compress = { .compress_pages = lzo_compress_pages, .decompress_bio = lzo_decompress_bio, .decompress = lzo_decompress, - .set_level = lzo_set_level, .max_level = 1, .default_level = 1, };
fs/btrfs/zlib.c +0 -9
@@ -418,14 +418,6 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in,return ret; } -static unsigned int zlib_set_level (unsigned int level) -{ -if (!level) -return BTRFS_ZLIB_DEFAULT_LEVEL ; - - return min_t(unsigned int, level, 9); -} -const struct btrfs_compress_op btrfs_zlib_compress = { .init_workspace_manager = zlib_init_workspace_manager, .cleanup_workspace_manager = zlib_cleanup_workspace_manager,
@@ -436,7 +428,6 @@ const struct btrfs_compress_op btrfs_zlib_compress = { .compress_pages = zlib_compress_pages, .decompress_bio = zlib_decompress_bio, .decompress = zlib_decompress, - .set_level = zlib_set_level, .max_level = 9, .default_level = BTRFS_ZLIB_DEFAULT_LEVEL, };
fs/btrfs/zstd.c +0 -9
@@ -710,14 +710,6 @@ static int zstd_decompress(struct list_head *ws, unsigned char *data_in,return ret; } -static unsigned int zstd_set_level (unsigned int level) -{ -if (!level) -return ZSTD_BTRFS_DEFAULT_LEVEL ; - - return min_t(unsigned int, level, ZSTD_BTRFS_MAX_LEVEL); -} -const struct btrfs_compress_op btrfs_zstd_compress = { .init_workspace_manager = zstd_init_workspace_manager, .cleanup_workspace_manager = zstd_cleanup_workspace_manager,
@@ -728,7 +720,6 @@ const struct btrfs_compress_op btrfs_zstd_compress = { .compress_pages = zstd_compress_pages, .decompress_bio = zstd_decompress_bio, .decompress = zstd_decompress, - .set_level = zstd_set_level, .max_level = ZSTD_BTRFS_MAX_LEVEL, .default_level = ZSTD_BTRFS_DEFAULT_LEVEL, };
Signature · 1 line
2.22.0
Re: [PATCH v2 2/2] btrfs: compression: replace set_level callbacks by a common helper
Quoted 69 lines · David Sterba
The
set_levelcallbacks do not do anything special and can be replaced by a helper that uses the levels defined in the tables.Signed-off-by David Sterba <[email protected]>--- fs/btrfs/compression.c | 20 ++++++++++++++++++-- fs/btrfs/compression.h | 9 ++------- fs/btrfs/lzo.c | 6 ------ fs/btrfs/zlib.c | 9 --------- fs/btrfs/zstd.c | 9 --------- 5 files changed, 20 insertions(+), 33 deletions(-)fs/btrfs/compression.c +18
-2@@ -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_get_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; }fs/btrfs/compression.h +0
-7@@ -156,13 +156,6 @@ struct btrfs_compress_op {unsigned long start_byte, size_t srclen, size_t destlen); -/* -* This bounds the level set by the user to be within range of a -* particular compression type. It returns the level that will be used -* if the level is out of bounds or the default if 0 is passed in. -*/ -unsigned int (*set_level)(unsigned int level); -/* Maximum level supported by the compression algorithm */ unsigned int max_level;unsigned int default_level;
fs/btrfs/compression.h extern const struct btrfs_compress_op btrfs_zstd_compress; · line 176
Quoted 5 lines
fs/btrfs/compression.h +2
-0@@ -179,6 +172,8 @@ extern const struct btrfs_compress_op btrfs_zstd_compress;const char *btrfs_compress_type2str (enum btrfs_compression_type type);bool btrfs_compress_is_valid_type (const char *str,size_t len); +unsigned int btrfs_compress_set_level (int type,unsigned level); +
btrfs_compress_set_level() is undefined.
Thanks, Anand
Quoted 82 lines
fs/btrfs/compression.h +0
-0int btrfs_compress_heuristic (struct inode *inode,u64 start,u64 end);#endif fs/btrfs/lzo.c +0
-6@@ -507,11 +507,6 @@ static int lzo_decompress(struct list_head *ws, unsigned char *data_in,return ret; } -static unsigned int lzo_set_level (unsigned int level) -{ -return 0 ; -} -const struct btrfs_compress_op btrfs_lzo_compress = { .init_workspace_manager = lzo_init_workspace_manager, .cleanup_workspace_manager = lzo_cleanup_workspace_manager,@@ -522,7 +517,6 @@ const struct btrfs_compress_op btrfs_lzo_compress = { .compress_pages = lzo_compress_pages, .decompress_bio = lzo_decompress_bio, .decompress = lzo_decompress, - .set_level = lzo_set_level, .max_level = 1, .default_level = 1, };fs/btrfs/zlib.c +0
-9@@ -418,14 +418,6 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in,return ret; } -static unsigned int zlib_set_level (unsigned int level) -{ -if (!level) -return BTRFS_ZLIB_DEFAULT_LEVEL ; - - return min_t(unsigned int, level, 9); -} -const struct btrfs_compress_op btrfs_zlib_compress = { .init_workspace_manager = zlib_init_workspace_manager, .cleanup_workspace_manager = zlib_cleanup_workspace_manager,@@ -436,7 +428,6 @@ const struct btrfs_compress_op btrfs_zlib_compress = { .compress_pages = zlib_compress_pages, .decompress_bio = zlib_decompress_bio, .decompress = zlib_decompress, - .set_level = zlib_set_level, .max_level = 9, .default_level = BTRFS_ZLIB_DEFAULT_LEVEL, };fs/btrfs/zstd.c +0
-9@@ -710,14 +710,6 @@ static int zstd_decompress(struct list_head *ws, unsigned char *data_in,return ret; } -static unsigned int zstd_set_level (unsigned int level) -{ -if (!level) -return ZSTD_BTRFS_DEFAULT_LEVEL ; - - return min_t(unsigned int, level, ZSTD_BTRFS_MAX_LEVEL); -} -const struct btrfs_compress_op btrfs_zstd_compress = { .init_workspace_manager = zstd_init_workspace_manager, .cleanup_workspace_manager = zstd_cleanup_workspace_manager,@@ -728,7 +720,6 @@ const struct btrfs_compress_op btrfs_zstd_compress = { .compress_pages = zstd_compress_pages, .decompress_bio = zstd_decompress_bio, .decompress = zstd_decompress, - .set_level = zstd_set_level, .max_level = ZSTD_BTRFS_MAX_LEVEL, .default_level = ZSTD_BTRFS_DEFAULT_LEVEL, };
Re: [PATCH v2 2/2] btrfs: compression: replace set_level callbacks by a common helper
Quoted 73 lines · Anand Jain
Quoted 72 lines · David Sterba
The
set_levelcallbacks do not do anything special and can be replaced by a helper that uses the levels defined in the tables.Signed-off-by David Sterba <[email protected]>--- fs/btrfs/compression.c | 20 ++++++++++++++++++-- fs/btrfs/compression.h | 9 ++------- fs/btrfs/lzo.c | 6 ------ fs/btrfs/zlib.c | 9 --------- fs/btrfs/zstd.c | 9 --------- 5 files changed, 20 insertions(+), 33 deletions(-)fs/btrfs/compression.c +18
-2@@ -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_get_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; }fs/btrfs/compression.h +0
-7@@ -156,13 +156,6 @@ struct btrfs_compress_op {unsigned long start_byte, size_t srclen, size_t destlen); -/* -* This bounds the level set by the user to be within range of a -* particular compression type. It returns the level that will be used -* if the level is out of bounds or the default if 0 is passed in. -*/ -unsigned int (*set_level)(unsigned int level); -/* Maximum level supported by the compression algorithm */ unsigned int max_level;unsigned int default_level;@@ -179,6 +172,8 @@ extern const struct btrfs_compress_op btrfs_zstd_compress;const char *btrfs_compress_type2str (enum btrfs_compression_type type);bool btrfs_compress_is_valid_type (const char *str,size_t len);
Quoted 4 lines
fs/btrfs/compression.h extern const struct btrfs_compress_op btrfs_zstd_compress; · line 176
Quoted 2 lines
fs/btrfs/compression.h +2
-0+unsigned int btrfs_compress_set_level (int type,unsigned level); +
btrfs_compress_set_level()is undefined.
Indeed, by some mistake the function is named btrfs_compress_get_level and my compiler does not care to fail the build.
Quoted 9 lines · David Sterba
Remove the callback indirection.
v2:
* switch to unsigned int and usemin()David Sterba (2):
btrfs: define compression levels statically
btrfs: compression: replaceset_levelcallbacks by a common helper
For the whole series:
Quoted 7 lines
fs/btrfs/compression.c | 20 ++++++++++++++++++-- fs/btrfs/compression.h | 11 +++++------ fs/btrfs/lzo.c | 8 ++------ fs/btrfs/zlib.c | 11 ++--------- fs/btrfs/zstd.c | 11 ++--------- 5 files changed, 29 insertions(+), 32 deletions(-)