summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/compress.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-07-12 22:27:16 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:10:07 -0400
commit986e9842fb6825f65918ed400b29c8c878359b7a (patch)
tree6a20a085db8f8c557879461c2154ee8f1790f4a3 /fs/bcachefs/compress.h
parente86e9124ca6c762f02cc412ce71feb9ed2e4890d (diff)
downloadlinux-986e9842fb6825f65918ed400b29c8c878359b7a.tar.gz
linux-986e9842fb6825f65918ed400b29c8c878359b7a.tar.bz2
linux-986e9842fb6825f65918ed400b29c8c878359b7a.zip
bcachefs: Compression levels
This allows including a compression level when specifying a compression type, e.g. compression=zstd:15 Values from 1 through 15 indicate compression levels, 0 or unspecified indicates the default. For LZ4, values 3-15 specify that the HC algorithm should be used. Note that for compatibility, extents themselves only include the compression type, not the compression level. This means that specifying the same compression algorithm but different compression levels for the compression and background_compression options will have no effect. XXX: perhaps we could add a warning for this Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/compress.h')
-rw-r--r--fs/bcachefs/compress.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/fs/bcachefs/compress.h b/fs/bcachefs/compress.h
index 4bab1f61b3b5..052ea303241f 100644
--- a/fs/bcachefs/compress.h
+++ b/fs/bcachefs/compress.h
@@ -4,6 +4,35 @@
#include "extents_types.h"
+struct bch_compression_opt {
+ u8 type:4,
+ level:4;
+};
+
+static inline struct bch_compression_opt bch2_compression_decode(unsigned v)
+{
+ return (struct bch_compression_opt) {
+ .type = v & 15,
+ .level = v >> 4,
+ };
+}
+
+static inline unsigned bch2_compression_encode(struct bch_compression_opt opt)
+{
+ return opt.type|(opt.level << 4);
+}
+
+static const unsigned __bch2_compression_opt_to_type[] = {
+#define x(t, n) [BCH_COMPRESSION_OPT_##t] = BCH_COMPRESSION_TYPE_##t,
+ BCH_COMPRESSION_OPTS()
+#undef x
+};
+
+static inline enum bch_compression_type bch2_compression_opt_to_type(unsigned v)
+{
+ return __bch2_compression_opt_to_type[bch2_compression_decode(v).type];
+}
+
int bch2_bio_uncompress_inplace(struct bch_fs *, struct bio *,
struct bch_extent_crc_unpacked *);
int bch2_bio_uncompress(struct bch_fs *, struct bio *, struct bio *,
@@ -15,4 +44,12 @@ int bch2_check_set_has_compressed_data(struct bch_fs *, unsigned);
void bch2_fs_compress_exit(struct bch_fs *);
int bch2_fs_compress_init(struct bch_fs *);
+int bch2_opt_compression_parse(struct bch_fs *, const char *, u64 *, struct printbuf *);
+void bch2_opt_compression_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
+
+#define bch2_opt_compression (struct bch_opt_fn) { \
+ .parse = bch2_opt_compression_parse, \
+ .to_text = bch2_opt_compression_to_text, \
+}
+
#endif /* _BCACHEFS_COMPRESS_H */