btrfs: rename btrfs_compress_op to btrfs_compress_levels

Since all workspace managers are per-fs, there is no need nor no way to
store them inside btrfs_compress_op::wsm anymore.

With that said, we can do the following modifications:

- Remove zstd_workspace_mananger::ops
  Zstd always grab the global btrfs_compress_op[].
- Remove btrfs_compress_op::wsm member
- Rename btrfs_compress_op to btrfs_compress_levels

This should make it more clear that btrfs_compress_levels structures are
only to indicate the levels of each compress algorithm.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Qu Wenruo 2025-08-14 10:35:23 +09:30 committed by David Sterba
parent 9c8f4cf456
commit 0d0b80929e
5 changed files with 15 additions and 18 deletions

View File

@ -727,9 +727,9 @@ fail:
return ERR_PTR(-ENOMEM);
}
const struct btrfs_compress_op btrfs_heuristic_compress = { 0 };
const struct btrfs_compress_levels btrfs_heuristic_compress = { 0 };
static const struct btrfs_compress_op * const btrfs_compress_op[] = {
static const struct btrfs_compress_levels * const btrfs_compress_levels[] = {
/* The heuristic is represented as compression type 0 */
&btrfs_heuristic_compress,
&btrfs_zlib_compress,
@ -981,12 +981,12 @@ static void put_workspace(struct btrfs_fs_info *fs_info, int type, struct list_h
*/
static int btrfs_compress_set_level(unsigned int type, int level)
{
const struct btrfs_compress_op *ops = btrfs_compress_op[type];
const struct btrfs_compress_levels *levels = btrfs_compress_levels[type];
if (level == 0)
level = ops->default_level;
level = levels->default_level;
else
level = clamp(level, ops->min_level, ops->max_level);
level = clamp(level, levels->min_level, levels->max_level);
return level;
}
@ -996,9 +996,9 @@ static int btrfs_compress_set_level(unsigned int type, int level)
*/
bool btrfs_compress_level_valid(unsigned int type, int level)
{
const struct btrfs_compress_op *ops = btrfs_compress_op[type];
const struct btrfs_compress_levels *levels = btrfs_compress_levels[type];
return ops->min_level <= level && level <= ops->max_level;
return levels->min_level <= level && level <= levels->max_level;
}
/* Wrapper around find_get_page(), with extra error message. */

View File

@ -129,8 +129,7 @@ struct workspace_manager {
struct list_head *btrfs_get_workspace(struct btrfs_fs_info *fs_info, int type, int level);
void btrfs_put_workspace(struct btrfs_fs_info *fs_info, int type, struct list_head *ws);
struct btrfs_compress_op {
struct workspace_manager *workspace_manager;
struct btrfs_compress_levels {
/* Maximum level supported by the compression algorithm */
int min_level;
int max_level;
@ -140,10 +139,10 @@ struct btrfs_compress_op {
/* The heuristic workspaces are managed via the 0th workspace manager */
#define BTRFS_NR_WORKSPACE_MANAGERS BTRFS_NR_COMPRESS_TYPES
extern const struct btrfs_compress_op btrfs_heuristic_compress;
extern const struct btrfs_compress_op btrfs_zlib_compress;
extern const struct btrfs_compress_op btrfs_lzo_compress;
extern const struct btrfs_compress_op btrfs_zstd_compress;
extern const struct btrfs_compress_levels btrfs_heuristic_compress;
extern const struct btrfs_compress_levels btrfs_zlib_compress;
extern const struct btrfs_compress_levels btrfs_lzo_compress;
extern const struct btrfs_compress_levels 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);

View File

@ -486,7 +486,7 @@ out:
return ret;
}
const struct btrfs_compress_op btrfs_lzo_compress = {
const struct btrfs_compress_levels btrfs_lzo_compress = {
.max_level = 1,
.default_level = 1,
};

View File

@ -480,7 +480,7 @@ out:
return ret;
}
const struct btrfs_compress_op btrfs_zlib_compress = {
const struct btrfs_compress_levels btrfs_zlib_compress = {
.min_level = 1,
.max_level = 9,
.default_level = BTRFS_ZLIB_DEFAULT_LEVEL,

View File

@ -77,7 +77,6 @@ struct workspace {
*/
struct zstd_workspace_manager {
const struct btrfs_compress_op *ops;
spinlock_t lock;
struct list_head lru_list;
struct list_head idle_ws[ZSTD_BTRFS_MAX_LEVEL];
@ -190,7 +189,6 @@ int zstd_alloc_workspace_manager(struct btrfs_fs_info *fs_info)
if (!zwsm)
return -ENOMEM;
zstd_calc_ws_mem_sizes();
zwsm->ops = &btrfs_zstd_compress;
spin_lock_init(&zwsm->lock);
init_waitqueue_head(&zwsm->wait);
timer_setup(&zwsm->timer, zstd_reclaim_timer_fn, 0);
@ -727,7 +725,7 @@ finish:
return ret;
}
const struct btrfs_compress_op btrfs_zstd_compress = {
const struct btrfs_compress_levels btrfs_zstd_compress = {
.min_level = ZSTD_BTRFS_MIN_LEVEL,
.max_level = ZSTD_BTRFS_MAX_LEVEL,
.default_level = ZSTD_BTRFS_DEFAULT_LEVEL,