1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef __BTRFS_COMPRESSION_
20#define __BTRFS_COMPRESSION_
21
22
23
24
25
26
27
28
29
30
31
32
33#define BTRFS_MAX_COMPRESSED (SZ_128K)
34
35#define BTRFS_MAX_UNCOMPRESSED (SZ_128K)
36
37struct compressed_bio {
38
39 refcount_t pending_bios;
40
41
42 struct page **compressed_pages;
43
44
45 struct inode *inode;
46
47
48 u64 start;
49
50
51 unsigned long len;
52
53
54 unsigned long compressed_len;
55
56
57 int compress_type;
58
59
60 unsigned long nr_pages;
61
62
63 int errors;
64 int mirror_num;
65
66
67 struct bio *orig_bio;
68
69
70
71
72
73 u32 sums;
74};
75
76void btrfs_init_compress(void);
77void btrfs_exit_compress(void);
78
79int btrfs_compress_pages(int type, struct address_space *mapping,
80 u64 start, struct page **pages,
81 unsigned long *out_pages,
82 unsigned long *total_in,
83 unsigned long *total_out);
84int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page,
85 unsigned long start_byte, size_t srclen, size_t destlen);
86int btrfs_decompress_buf2page(const char *buf, unsigned long buf_start,
87 unsigned long total_out, u64 disk_start,
88 struct bio *bio);
89
90blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start,
91 unsigned long len, u64 disk_start,
92 unsigned long compressed_len,
93 struct page **compressed_pages,
94 unsigned long nr_pages);
95blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
96 int mirror_num, unsigned long bio_flags);
97
98enum btrfs_compression_type {
99 BTRFS_COMPRESS_NONE = 0,
100 BTRFS_COMPRESS_ZLIB = 1,
101 BTRFS_COMPRESS_LZO = 2,
102 BTRFS_COMPRESS_TYPES = 2,
103 BTRFS_COMPRESS_LAST = 3,
104};
105
106struct btrfs_compress_op {
107 struct list_head *(*alloc_workspace)(void);
108
109 void (*free_workspace)(struct list_head *workspace);
110
111 int (*compress_pages)(struct list_head *workspace,
112 struct address_space *mapping,
113 u64 start,
114 struct page **pages,
115 unsigned long *out_pages,
116 unsigned long *total_in,
117 unsigned long *total_out);
118
119 int (*decompress_bio)(struct list_head *workspace,
120 struct compressed_bio *cb);
121
122 int (*decompress)(struct list_head *workspace,
123 unsigned char *data_in,
124 struct page *dest_page,
125 unsigned long start_byte,
126 size_t srclen, size_t destlen);
127};
128
129extern const struct btrfs_compress_op btrfs_zlib_compress;
130extern const struct btrfs_compress_op btrfs_lzo_compress;
131
132#endif
133