aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorZach Brown <zab@redhat.com>2014-05-09 17:15:08 -0400
committerChris Mason <clm@fb.com>2014-06-09 20:20:21 -0400
commit60e1975acb48fc3d74a3422b21dde74c977ac3d5 (patch)
treeeee37a1df3a53564e3d38d15d65d63c0a437e9c7 /fs/btrfs
parent98806b446db8f15e83b59d065dae62901138e5cb (diff)
btrfs: return errno instead of -1 from compression
The compression layer seems to have been built to return -1 and have callers make up errors that make sense. This isn't great because there are different errors that originate down in the compression layer. Let's return real negative errnos from the compression layer so that callers can pass on the error without having to guess what happened. ENOMEM for allocation failure, E2BIG when compression exceeds the uncompressed input, and EIO for everything else. This helps a future path return errors from btrfs_decompress(). Signed-off-by: Zach Brown <zab@redhat.com> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/lzo.c14
-rw-r--r--fs/btrfs/zlib.c26
2 files changed, 20 insertions, 20 deletions
diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index b47f669aca75..dfad8514f0da 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -143,7 +143,7 @@ static int lzo_compress_pages(struct list_head *ws,
143 if (ret != LZO_E_OK) { 143 if (ret != LZO_E_OK) {
144 printk(KERN_DEBUG "BTRFS: deflate in loop returned %d\n", 144 printk(KERN_DEBUG "BTRFS: deflate in loop returned %d\n",
145 ret); 145 ret);
146 ret = -1; 146 ret = -EIO;
147 goto out; 147 goto out;
148 } 148 }
149 149
@@ -189,7 +189,7 @@ static int lzo_compress_pages(struct list_head *ws,
189 kunmap(out_page); 189 kunmap(out_page);
190 if (nr_pages == nr_dest_pages) { 190 if (nr_pages == nr_dest_pages) {
191 out_page = NULL; 191 out_page = NULL;
192 ret = -1; 192 ret = -E2BIG;
193 goto out; 193 goto out;
194 } 194 }
195 195
@@ -208,7 +208,7 @@ static int lzo_compress_pages(struct list_head *ws,
208 208
209 /* we're making it bigger, give up */ 209 /* we're making it bigger, give up */
210 if (tot_in > 8192 && tot_in < tot_out) { 210 if (tot_in > 8192 && tot_in < tot_out) {
211 ret = -1; 211 ret = -E2BIG;
212 goto out; 212 goto out;
213 } 213 }
214 214
@@ -335,7 +335,7 @@ cont:
335 break; 335 break;
336 336
337 if (page_in_index + 1 >= total_pages_in) { 337 if (page_in_index + 1 >= total_pages_in) {
338 ret = -1; 338 ret = -EIO;
339 goto done; 339 goto done;
340 } 340 }
341 341
@@ -358,7 +358,7 @@ cont:
358 kunmap(pages_in[page_in_index - 1]); 358 kunmap(pages_in[page_in_index - 1]);
359 if (ret != LZO_E_OK) { 359 if (ret != LZO_E_OK) {
360 printk(KERN_WARNING "BTRFS: decompress failed\n"); 360 printk(KERN_WARNING "BTRFS: decompress failed\n");
361 ret = -1; 361 ret = -EIO;
362 break; 362 break;
363 } 363 }
364 364
@@ -402,12 +402,12 @@ static int lzo_decompress(struct list_head *ws, unsigned char *data_in,
402 ret = lzo1x_decompress_safe(data_in, in_len, workspace->buf, &out_len); 402 ret = lzo1x_decompress_safe(data_in, in_len, workspace->buf, &out_len);
403 if (ret != LZO_E_OK) { 403 if (ret != LZO_E_OK) {
404 printk(KERN_WARNING "BTRFS: decompress failed!\n"); 404 printk(KERN_WARNING "BTRFS: decompress failed!\n");
405 ret = -1; 405 ret = -EIO;
406 goto out; 406 goto out;
407 } 407 }
408 408
409 if (out_len < start_byte) { 409 if (out_len < start_byte) {
410 ret = -1; 410 ret = -EIO;
411 goto out; 411 goto out;
412 } 412 }
413 413
diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
index 8e57191950cb..4f196314c0c1 100644
--- a/fs/btrfs/zlib.c
+++ b/fs/btrfs/zlib.c
@@ -98,7 +98,7 @@ static int zlib_compress_pages(struct list_head *ws,
98 98
99 if (Z_OK != zlib_deflateInit(&workspace->def_strm, 3)) { 99 if (Z_OK != zlib_deflateInit(&workspace->def_strm, 3)) {
100 printk(KERN_WARNING "BTRFS: deflateInit failed\n"); 100 printk(KERN_WARNING "BTRFS: deflateInit failed\n");
101 ret = -1; 101 ret = -EIO;
102 goto out; 102 goto out;
103 } 103 }
104 104
@@ -110,7 +110,7 @@ static int zlib_compress_pages(struct list_head *ws,
110 110
111 out_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM); 111 out_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM);
112 if (out_page == NULL) { 112 if (out_page == NULL) {
113 ret = -1; 113 ret = -ENOMEM;
114 goto out; 114 goto out;
115 } 115 }
116 cpage_out = kmap(out_page); 116 cpage_out = kmap(out_page);
@@ -128,7 +128,7 @@ static int zlib_compress_pages(struct list_head *ws,
128 printk(KERN_DEBUG "BTRFS: deflate in loop returned %d\n", 128 printk(KERN_DEBUG "BTRFS: deflate in loop returned %d\n",
129 ret); 129 ret);
130 zlib_deflateEnd(&workspace->def_strm); 130 zlib_deflateEnd(&workspace->def_strm);
131 ret = -1; 131 ret = -EIO;
132 goto out; 132 goto out;
133 } 133 }
134 134
@@ -136,7 +136,7 @@ static int zlib_compress_pages(struct list_head *ws,
136 if (workspace->def_strm.total_in > 8192 && 136 if (workspace->def_strm.total_in > 8192 &&
137 workspace->def_strm.total_in < 137 workspace->def_strm.total_in <
138 workspace->def_strm.total_out) { 138 workspace->def_strm.total_out) {
139 ret = -1; 139 ret = -EIO;
140 goto out; 140 goto out;
141 } 141 }
142 /* we need another page for writing out. Test this 142 /* we need another page for writing out. Test this
@@ -147,12 +147,12 @@ static int zlib_compress_pages(struct list_head *ws,
147 kunmap(out_page); 147 kunmap(out_page);
148 if (nr_pages == nr_dest_pages) { 148 if (nr_pages == nr_dest_pages) {
149 out_page = NULL; 149 out_page = NULL;
150 ret = -1; 150 ret = -E2BIG;
151 goto out; 151 goto out;
152 } 152 }
153 out_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM); 153 out_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM);
154 if (out_page == NULL) { 154 if (out_page == NULL) {
155 ret = -1; 155 ret = -ENOMEM;
156 goto out; 156 goto out;
157 } 157 }
158 cpage_out = kmap(out_page); 158 cpage_out = kmap(out_page);
@@ -188,12 +188,12 @@ static int zlib_compress_pages(struct list_head *ws,
188 zlib_deflateEnd(&workspace->def_strm); 188 zlib_deflateEnd(&workspace->def_strm);
189 189
190 if (ret != Z_STREAM_END) { 190 if (ret != Z_STREAM_END) {
191 ret = -1; 191 ret = -EIO;
192 goto out; 192 goto out;
193 } 193 }
194 194
195 if (workspace->def_strm.total_out >= workspace->def_strm.total_in) { 195 if (workspace->def_strm.total_out >= workspace->def_strm.total_in) {
196 ret = -1; 196 ret = -E2BIG;
197 goto out; 197 goto out;
198 } 198 }
199 199
@@ -253,7 +253,7 @@ static int zlib_decompress_biovec(struct list_head *ws, struct page **pages_in,
253 253
254 if (Z_OK != zlib_inflateInit2(&workspace->inf_strm, wbits)) { 254 if (Z_OK != zlib_inflateInit2(&workspace->inf_strm, wbits)) {
255 printk(KERN_WARNING "BTRFS: inflateInit failed\n"); 255 printk(KERN_WARNING "BTRFS: inflateInit failed\n");
256 return -1; 256 return -EIO;
257 } 257 }
258 while (workspace->inf_strm.total_in < srclen) { 258 while (workspace->inf_strm.total_in < srclen) {
259 ret = zlib_inflate(&workspace->inf_strm, Z_NO_FLUSH); 259 ret = zlib_inflate(&workspace->inf_strm, Z_NO_FLUSH);
@@ -295,7 +295,7 @@ static int zlib_decompress_biovec(struct list_head *ws, struct page **pages_in,
295 } 295 }
296 } 296 }
297 if (ret != Z_STREAM_END) 297 if (ret != Z_STREAM_END)
298 ret = -1; 298 ret = -EIO;
299 else 299 else
300 ret = 0; 300 ret = 0;
301done: 301done:
@@ -337,7 +337,7 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in,
337 337
338 if (Z_OK != zlib_inflateInit2(&workspace->inf_strm, wbits)) { 338 if (Z_OK != zlib_inflateInit2(&workspace->inf_strm, wbits)) {
339 printk(KERN_WARNING "BTRFS: inflateInit failed\n"); 339 printk(KERN_WARNING "BTRFS: inflateInit failed\n");
340 return -1; 340 return -EIO;
341 } 341 }
342 342
343 while (bytes_left > 0) { 343 while (bytes_left > 0) {
@@ -354,7 +354,7 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in,
354 total_out = workspace->inf_strm.total_out; 354 total_out = workspace->inf_strm.total_out;
355 355
356 if (total_out == buf_start) { 356 if (total_out == buf_start) {
357 ret = -1; 357 ret = -EIO;
358 break; 358 break;
359 } 359 }
360 360
@@ -382,7 +382,7 @@ next:
382 } 382 }
383 383
384 if (ret != Z_STREAM_END && bytes_left != 0) 384 if (ret != Z_STREAM_END && bytes_left != 0)
385 ret = -1; 385 ret = -EIO;
386 else 386 else
387 ret = 0; 387 ret = 0;
388 388