summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/compression.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/compression.c')
-rw-r--r--fs/btrfs/compression.c43
1 files changed, 19 insertions, 24 deletions
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 903c32c9eb22..c7721a6aa3bb 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -100,7 +100,7 @@ static struct bio *compressed_bio_alloc(struct block_device *bdev,
100 return btrfs_bio_alloc(bdev, first_byte >> 9, BIO_MAX_PAGES, gfp_flags); 100 return btrfs_bio_alloc(bdev, first_byte >> 9, BIO_MAX_PAGES, gfp_flags);
101} 101}
102 102
103static int check_compressed_csum(struct inode *inode, 103static int check_compressed_csum(struct btrfs_inode *inode,
104 struct compressed_bio *cb, 104 struct compressed_bio *cb,
105 u64 disk_start) 105 u64 disk_start)
106{ 106{
@@ -111,7 +111,7 @@ static int check_compressed_csum(struct inode *inode,
111 u32 csum; 111 u32 csum;
112 u32 *cb_sum = &cb->sums; 112 u32 *cb_sum = &cb->sums;
113 113
114 if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) 114 if (inode->flags & BTRFS_INODE_NODATASUM)
115 return 0; 115 return 0;
116 116
117 for (i = 0; i < cb->nr_pages; i++) { 117 for (i = 0; i < cb->nr_pages; i++) {
@@ -125,7 +125,7 @@ static int check_compressed_csum(struct inode *inode,
125 125
126 if (csum != *cb_sum) { 126 if (csum != *cb_sum) {
127 btrfs_print_data_csum_error(inode, disk_start, csum, 127 btrfs_print_data_csum_error(inode, disk_start, csum,
128 *cb_sum, cb->mirror_num); 128 *cb_sum, cb->mirror_num);
129 ret = -EIO; 129 ret = -EIO;
130 goto fail; 130 goto fail;
131 } 131 }
@@ -165,7 +165,7 @@ static void end_compressed_bio_read(struct bio *bio)
165 goto out; 165 goto out;
166 166
167 inode = cb->inode; 167 inode = cb->inode;
168 ret = check_compressed_csum(inode, cb, 168 ret = check_compressed_csum(BTRFS_I(inode), cb,
169 (u64)bio->bi_iter.bi_sector << 9); 169 (u64)bio->bi_iter.bi_sector << 9);
170 if (ret) 170 if (ret)
171 goto csum_failed; 171 goto csum_failed;
@@ -911,32 +911,28 @@ static void free_workspaces(void)
911} 911}
912 912
913/* 913/*
914 * given an address space and start/len, compress the bytes. 914 * Given an address space and start and length, compress the bytes into @pages
915 * that are allocated on demand.
915 * 916 *
916 * pages are allocated to hold the compressed result and stored 917 * @out_pages is an in/out parameter, holds maximum number of pages to allocate
917 * in 'pages' 918 * and returns number of actually allocated pages
918 * 919 *
919 * out_pages is used to return the number of pages allocated. There 920 * @total_in is used to return the number of bytes actually read. It
920 * may be pages allocated even if we return an error 921 * may be smaller than the input length if we had to exit early because we
921 *
922 * total_in is used to return the number of bytes actually read. It
923 * may be smaller then len if we had to exit early because we
924 * ran out of room in the pages array or because we cross the 922 * ran out of room in the pages array or because we cross the
925 * max_out threshold. 923 * max_out threshold.
926 * 924 *
927 * total_out is used to return the total number of compressed bytes 925 * @total_out is an in/out parameter, must be set to the input length and will
926 * be also used to return the total number of compressed bytes
928 * 927 *
929 * max_out tells us the max number of bytes that we're allowed to 928 * @max_out tells us the max number of bytes that we're allowed to
930 * stuff into pages 929 * stuff into pages
931 */ 930 */
932int btrfs_compress_pages(int type, struct address_space *mapping, 931int btrfs_compress_pages(int type, struct address_space *mapping,
933 u64 start, unsigned long len, 932 u64 start, struct page **pages,
934 struct page **pages,
935 unsigned long nr_dest_pages,
936 unsigned long *out_pages, 933 unsigned long *out_pages,
937 unsigned long *total_in, 934 unsigned long *total_in,
938 unsigned long *total_out, 935 unsigned long *total_out)
939 unsigned long max_out)
940{ 936{
941 struct list_head *workspace; 937 struct list_head *workspace;
942 int ret; 938 int ret;
@@ -944,10 +940,9 @@ int btrfs_compress_pages(int type, struct address_space *mapping,
944 workspace = find_workspace(type); 940 workspace = find_workspace(type);
945 941
946 ret = btrfs_compress_op[type-1]->compress_pages(workspace, mapping, 942 ret = btrfs_compress_op[type-1]->compress_pages(workspace, mapping,
947 start, len, pages, 943 start, pages,
948 nr_dest_pages, out_pages, 944 out_pages,
949 total_in, total_out, 945 total_in, total_out);
950 max_out);
951 free_workspace(type, workspace); 946 free_workspace(type, workspace);
952 return ret; 947 return ret;
953} 948}
@@ -1015,7 +1010,7 @@ void btrfs_exit_compress(void)
1015 * 1010 *
1016 * total_out is the last byte of the buffer 1011 * total_out is the last byte of the buffer
1017 */ 1012 */
1018int btrfs_decompress_buf2page(char *buf, unsigned long buf_start, 1013int btrfs_decompress_buf2page(const char *buf, unsigned long buf_start,
1019 unsigned long total_out, u64 disk_start, 1014 unsigned long total_out, u64 disk_start,
1020 struct bio *bio) 1015 struct bio *bio)
1021{ 1016{