From 92ee55303616a18135be91deff51799a5de81f9a Mon Sep 17 00:00:00 2001 From: Dennis Zhou Date: Mon, 4 Feb 2019 15:20:03 -0500 Subject: 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 Signed-off-by: Dennis Zhou Reviewed-by: David Sterba Signed-off-by: David Sterba --- fs/btrfs/zstd.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'fs/btrfs/zstd.c') diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index af6ec59972f5..b06eaf171be7 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -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, -- cgit v1.2.3