1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _BCACHEFS_COMPRESS_H 3 #define _BCACHEFS_COMPRESS_H 4 5 #include "extents_types.h" 6 7 struct bch_compression_opt { 8 u8 type:4, 9 level:4; 10 }; 11 12 static inline struct bch_compression_opt bch2_compression_decode(unsigned v) 13 { 14 return (struct bch_compression_opt) { 15 .type = v & 15, 16 .level = v >> 4, 17 }; 18 } 19 20 static inline unsigned bch2_compression_encode(struct bch_compression_opt opt) 21 { 22 return opt.type|(opt.level << 4); 23 } 24 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() 28 #undef x 29 }; 30 31 static inline enum bch_compression_type bch2_compression_opt_to_type(unsigned v) 32 { 33 return __bch2_compression_opt_to_type[bch2_compression_decode(v).type]; 34 } 35 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); 42 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 *); 46 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); 49 50 #define bch2_opt_compression (struct bch_opt_fn) { \ 51 .parse = bch2_opt_compression_parse, \ 52 .to_text = bch2_opt_compression_to_text, \ 53 } 54 55 #endif /* _BCACHEFS_COMPRESS_H */ 56