mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-07 13:53:24 +00:00
f2fs: add helper to check compression level
This patch adds a helper function to check if compression level is valid. Signed-off-by: Sheng Yong <shengyong@oppo.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
94c8431fb4
commit
c571fbb5b5
@ -55,6 +55,7 @@ struct f2fs_compress_ops {
|
|||||||
int (*init_decompress_ctx)(struct decompress_io_ctx *dic);
|
int (*init_decompress_ctx)(struct decompress_io_ctx *dic);
|
||||||
void (*destroy_decompress_ctx)(struct decompress_io_ctx *dic);
|
void (*destroy_decompress_ctx)(struct decompress_io_ctx *dic);
|
||||||
int (*decompress_pages)(struct decompress_io_ctx *dic);
|
int (*decompress_pages)(struct decompress_io_ctx *dic);
|
||||||
|
bool (*is_level_valid)(int level);
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned int offset_in_cluster(struct compress_ctx *cc, pgoff_t index)
|
static unsigned int offset_in_cluster(struct compress_ctx *cc, pgoff_t index)
|
||||||
@ -308,11 +309,21 @@ static int lz4_decompress_pages(struct decompress_io_ctx *dic)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool lz4_is_level_valid(int lvl)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_F2FS_FS_LZ4HC
|
||||||
|
return !lvl || (lvl >= LZ4HC_MIN_CLEVEL && lvl <= LZ4HC_MAX_CLEVEL);
|
||||||
|
#else
|
||||||
|
return lvl == 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static const struct f2fs_compress_ops f2fs_lz4_ops = {
|
static const struct f2fs_compress_ops f2fs_lz4_ops = {
|
||||||
.init_compress_ctx = lz4_init_compress_ctx,
|
.init_compress_ctx = lz4_init_compress_ctx,
|
||||||
.destroy_compress_ctx = lz4_destroy_compress_ctx,
|
.destroy_compress_ctx = lz4_destroy_compress_ctx,
|
||||||
.compress_pages = lz4_compress_pages,
|
.compress_pages = lz4_compress_pages,
|
||||||
.decompress_pages = lz4_decompress_pages,
|
.decompress_pages = lz4_decompress_pages,
|
||||||
|
.is_level_valid = lz4_is_level_valid,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -476,6 +487,11 @@ static int zstd_decompress_pages(struct decompress_io_ctx *dic)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool zstd_is_level_valid(int lvl)
|
||||||
|
{
|
||||||
|
return lvl >= zstd_min_clevel() && lvl <= zstd_max_clevel();
|
||||||
|
}
|
||||||
|
|
||||||
static const struct f2fs_compress_ops f2fs_zstd_ops = {
|
static const struct f2fs_compress_ops f2fs_zstd_ops = {
|
||||||
.init_compress_ctx = zstd_init_compress_ctx,
|
.init_compress_ctx = zstd_init_compress_ctx,
|
||||||
.destroy_compress_ctx = zstd_destroy_compress_ctx,
|
.destroy_compress_ctx = zstd_destroy_compress_ctx,
|
||||||
@ -483,6 +499,7 @@ static const struct f2fs_compress_ops f2fs_zstd_ops = {
|
|||||||
.init_decompress_ctx = zstd_init_decompress_ctx,
|
.init_decompress_ctx = zstd_init_decompress_ctx,
|
||||||
.destroy_decompress_ctx = zstd_destroy_decompress_ctx,
|
.destroy_decompress_ctx = zstd_destroy_decompress_ctx,
|
||||||
.decompress_pages = zstd_decompress_pages,
|
.decompress_pages = zstd_decompress_pages,
|
||||||
|
.is_level_valid = zstd_is_level_valid,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -541,6 +558,16 @@ bool f2fs_is_compress_backend_ready(struct inode *inode)
|
|||||||
return f2fs_cops[F2FS_I(inode)->i_compress_algorithm];
|
return f2fs_cops[F2FS_I(inode)->i_compress_algorithm];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool f2fs_is_compress_level_valid(int alg, int lvl)
|
||||||
|
{
|
||||||
|
const struct f2fs_compress_ops *cops = f2fs_cops[alg];
|
||||||
|
|
||||||
|
if (cops->is_level_valid)
|
||||||
|
return cops->is_level_valid(lvl);
|
||||||
|
|
||||||
|
return lvl == 0;
|
||||||
|
}
|
||||||
|
|
||||||
static mempool_t *compress_page_pool;
|
static mempool_t *compress_page_pool;
|
||||||
static int num_compress_pages = 512;
|
static int num_compress_pages = 512;
|
||||||
module_param(num_compress_pages, uint, 0444);
|
module_param(num_compress_pages, uint, 0444);
|
||||||
|
@ -4240,6 +4240,7 @@ bool f2fs_compress_write_end(struct inode *inode, void *fsdata,
|
|||||||
int f2fs_truncate_partial_cluster(struct inode *inode, u64 from, bool lock);
|
int f2fs_truncate_partial_cluster(struct inode *inode, u64 from, bool lock);
|
||||||
void f2fs_compress_write_end_io(struct bio *bio, struct page *page);
|
void f2fs_compress_write_end_io(struct bio *bio, struct page *page);
|
||||||
bool f2fs_is_compress_backend_ready(struct inode *inode);
|
bool f2fs_is_compress_backend_ready(struct inode *inode);
|
||||||
|
bool f2fs_is_compress_level_valid(int alg, int lvl);
|
||||||
int __init f2fs_init_compress_mempool(void);
|
int __init f2fs_init_compress_mempool(void);
|
||||||
void f2fs_destroy_compress_mempool(void);
|
void f2fs_destroy_compress_mempool(void);
|
||||||
void f2fs_decompress_cluster(struct decompress_io_ctx *dic, bool in_task);
|
void f2fs_decompress_cluster(struct decompress_io_ctx *dic, bool in_task);
|
||||||
@ -4304,6 +4305,7 @@ static inline bool f2fs_is_compress_backend_ready(struct inode *inode)
|
|||||||
/* not support compression */
|
/* not support compression */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
static inline bool f2fs_is_compress_level_valid(int alg, int lvl) { return false; }
|
||||||
static inline struct page *f2fs_compress_control_page(struct page *page)
|
static inline struct page *f2fs_compress_control_page(struct page *page)
|
||||||
{
|
{
|
||||||
WARN_ON_ONCE(1);
|
WARN_ON_ONCE(1);
|
||||||
|
@ -604,7 +604,7 @@ static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str)
|
|||||||
if (kstrtouint(str + 1, 10, &level))
|
if (kstrtouint(str + 1, 10, &level))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (level < LZ4HC_MIN_CLEVEL || level > LZ4HC_MAX_CLEVEL) {
|
if (!f2fs_is_compress_level_valid(COMPRESS_LZ4, level)) {
|
||||||
f2fs_info(sbi, "invalid lz4hc compress level: %d", level);
|
f2fs_info(sbi, "invalid lz4hc compress level: %d", level);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@ -642,7 +642,7 @@ static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str)
|
|||||||
if (kstrtouint(str + 1, 10, &level))
|
if (kstrtouint(str + 1, 10, &level))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (level < zstd_min_clevel() || level > zstd_max_clevel()) {
|
if (!f2fs_is_compress_level_valid(COMPRESS_ZSTD, level)) {
|
||||||
f2fs_info(sbi, "invalid zstd compress level: %d", level);
|
f2fs_info(sbi, "invalid zstd compress level: %d", level);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user