btrfs: plumb level through the compression interface
[sfrench/cifs-2.6.git] / fs / btrfs / compression.h
index ddda9b80bf2044edc3ae210bb401ce8e728fdbe2..2ab8b2f29d88aea9197f044fd6f833950405de37 100644 (file)
@@ -64,6 +64,16 @@ struct compressed_bio {
        u32 sums;
 };
 
+static inline unsigned int btrfs_compress_type(unsigned int type_level)
+{
+       return (type_level & 0xF);
+}
+
+static inline unsigned int btrfs_compress_level(unsigned int type_level)
+{
+       return ((type_level & 0xF0) >> 4);
+}
+
 void __init btrfs_init_compress(void);
 void __cold btrfs_exit_compress(void);
 
@@ -97,8 +107,35 @@ enum btrfs_compression_type {
        BTRFS_COMPRESS_TYPES = 3,
 };
 
+struct workspace_manager {
+       const struct btrfs_compress_op *ops;
+       struct list_head idle_ws;
+       spinlock_t ws_lock;
+       /* Number of free workspaces */
+       int free_ws;
+       /* Total number of allocated workspaces */
+       atomic_t total_ws;
+       /* Waiters for a free workspace */
+       wait_queue_head_t ws_wait;
+};
+
+void btrfs_init_workspace_manager(struct workspace_manager *wsm,
+                                 const struct btrfs_compress_op *ops);
+struct list_head *btrfs_get_workspace(struct workspace_manager *wsm,
+                                     unsigned int level);
+void btrfs_put_workspace(struct workspace_manager *wsm, struct list_head *ws);
+void btrfs_cleanup_workspace_manager(struct workspace_manager *wsm);
+
 struct btrfs_compress_op {
-       struct list_head *(*alloc_workspace)(void);
+       void (*init_workspace_manager)(void);
+
+       void (*cleanup_workspace_manager)(void);
+
+       struct list_head *(*get_workspace)(unsigned int level);
+
+       void (*put_workspace)(struct list_head *ws);
+
+       struct list_head *(*alloc_workspace)(unsigned int level);
 
        void (*free_workspace)(struct list_head *workspace);
 
@@ -122,6 +159,10 @@ struct btrfs_compress_op {
        void (*set_level)(struct list_head *ws, unsigned int type);
 };
 
+/* The heuristic workspaces are managed via the 0th workspace manager */
+#define BTRFS_NR_WORKSPACE_MANAGERS    (BTRFS_COMPRESS_TYPES + 1)
+
+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;