1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_COMPRESS_H
3 #define _BCACHEFS_COMPRESS_H
5 #include "extents_types.h"
7 struct bch_compression_opt {
12 static inline struct bch_compression_opt bch2_compression_decode(unsigned v)
14 return (struct bch_compression_opt) {
20 static inline unsigned bch2_compression_encode(struct bch_compression_opt opt)
22 return opt.type|(opt.level << 4);
25 static const unsigned __bch2_compression_opt_to_type[] = {
26 #define x(t, n) [BCH_COMPRESSION_OPT_##t] = BCH_COMPRESSION_TYPE_##t,
27 BCH_COMPRESSION_OPTS()
31 static inline enum bch_compression_type bch2_compression_opt_to_type(unsigned v)
33 return __bch2_compression_opt_to_type[bch2_compression_decode(v).type];
36 int bch2_bio_uncompress_inplace(struct bch_fs *, struct bio *,
37 struct bch_extent_crc_unpacked *);
38 int bch2_bio_uncompress(struct bch_fs *, struct bio *, struct bio *,
39 struct bvec_iter, struct bch_extent_crc_unpacked);
40 unsigned bch2_bio_compress(struct bch_fs *, struct bio *, size_t *,
41 struct bio *, size_t *, unsigned);
43 int bch2_check_set_has_compressed_data(struct bch_fs *, unsigned);
44 void bch2_fs_compress_exit(struct bch_fs *);
45 int bch2_fs_compress_init(struct bch_fs *);
47 int bch2_opt_compression_parse(struct bch_fs *, const char *, u64 *, struct printbuf *);
48 void bch2_opt_compression_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
50 #define bch2_opt_compression (struct bch_opt_fn) { \
51 .parse = bch2_opt_compression_parse, \
52 .to_text = bch2_opt_compression_to_text, \
55 #endif /* _BCACHEFS_COMPRESS_H */