const struct btrfs_compress_op btrfs_heuristic_compress = {
.workspace_manager = &heuristic_wsm,
- .free_workspace = free_heuristic_ws,
};
static const struct btrfs_compress_op * const btrfs_compress_op[] = {
}
}
+static void free_workspace(int type, struct list_head *ws)
+{
+ switch (type) {
+ case BTRFS_COMPRESS_NONE: return free_heuristic_ws(ws);
+ case BTRFS_COMPRESS_ZLIB: return zlib_free_workspace(ws);
+ case BTRFS_COMPRESS_LZO: return lzo_free_workspace(ws);
+ case BTRFS_COMPRESS_ZSTD: return zstd_free_workspace(ws);
+ default:
+ /*
+ * This can't happen, the type is validated several times
+ * before we get here.
+ */
+ BUG();
+ }
+}
+
static void btrfs_init_workspace_manager(int type)
{
const struct btrfs_compress_op *ops = btrfs_compress_op[type];
while (!list_empty(&wsman->idle_ws)) {
ws = wsman->idle_ws.next;
list_del(ws);
- wsman->ops->free_workspace(ws);
+ free_workspace(type, ws);
atomic_dec(&wsman->total_ws);
}
}
}
spin_unlock(ws_lock);
- wsm->ops->free_workspace(ws);
+ free_workspace(type, ws);
atomic_dec(total_ws);
wake:
cond_wake_up(ws_wait);
void btrfs_put_workspace(int type, struct list_head *ws);
struct btrfs_compress_op {
- void (*free_workspace)(struct list_head *workspace);
-
struct workspace_manager *workspace_manager;
/* Maximum level supported by the compression algorithm */
unsigned int max_level;
const struct btrfs_compress_op btrfs_lzo_compress = {
.workspace_manager = &wsm,
- .free_workspace = lzo_free_workspace,
.max_level = 1,
.default_level = 1,
};
const struct btrfs_compress_op btrfs_zlib_compress = {
.workspace_manager = &wsm,
- .free_workspace = zlib_free_workspace,
.max_level = 9,
.default_level = BTRFS_ZLIB_DEFAULT_LEVEL,
};
const struct btrfs_compress_op btrfs_zstd_compress = {
/* ZSTD uses own workspace manager */
.workspace_manager = NULL,
- .free_workspace = zstd_free_workspace,
.max_level = ZSTD_BTRFS_MAX_LEVEL,
.default_level = ZSTD_BTRFS_DEFAULT_LEVEL,
};