btrfs: move to function pointers for get/put workspaces

The previous patch added generic helpers for get_workspace() and
put_workspace(). Now, we can migrate ownership of the workspace_manager
to be in the compression type code as the compression code itself
doesn't care beyond being able to get a workspace. The init/cleanup and
get/put methods are abstracted so each compression algorithm can decide
how they want to manage their workspaces.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Dennis Zhou <dennis@kernel.org>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Dennis Zhou
2019-02-04 15:20:03 -05:00
committed by David Sterba
parent 929f4baf93
commit 92ee553036
5 changed files with 160 additions and 45 deletions

View File

@@ -41,6 +41,28 @@ struct workspace {
ZSTD_outBuffer out_buf;
};
static struct workspace_manager wsm;
static void zstd_init_workspace_manager(void)
{
btrfs_init_workspace_manager(&wsm, &btrfs_zstd_compress);
}
static void zstd_cleanup_workspace_manager(void)
{
btrfs_cleanup_workspace_manager(&wsm);
}
static struct list_head *zstd_get_workspace(void)
{
return btrfs_get_workspace(&wsm);
}
static void zstd_put_workspace(struct list_head *ws)
{
btrfs_put_workspace(&wsm, ws);
}
static void zstd_free_workspace(struct list_head *ws)
{
struct workspace *workspace = list_entry(ws, struct workspace, list);
@@ -424,6 +446,10 @@ static void zstd_set_level(struct list_head *ws, unsigned int type)
}
const struct btrfs_compress_op btrfs_zstd_compress = {
.init_workspace_manager = zstd_init_workspace_manager,
.cleanup_workspace_manager = zstd_cleanup_workspace_manager,
.get_workspace = zstd_get_workspace,
.put_workspace = zstd_put_workspace,
.alloc_workspace = zstd_alloc_workspace,
.free_workspace = zstd_free_workspace,
.compress_pages = zstd_compress_pages,