summaryrefslogtreecommitdiff
path: root/fs/bcachefs/compress.h
blob: 052ea303241fc31407edde0bcc2d3037d7691137 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _BCACHEFS_COMPRESS_H
#define _BCACHEFS_COMPRESS_H

#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 *,
		       struct bvec_iter, struct bch_extent_crc_unpacked);
unsigned bch2_bio_compress(struct bch_fs *, struct bio *, size_t *,
			   struct bio *, size_t *, unsigned);

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 */