diff options
author | Zach Brown <zab@redhat.com> | 2014-05-09 17:15:08 -0400 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2014-06-09 20:20:21 -0400 |
commit | 60e1975acb48fc3d74a3422b21dde74c977ac3d5 (patch) | |
tree | eee37a1df3a53564e3d38d15d65d63c0a437e9c7 /fs/btrfs/zlib.c | |
parent | 98806b446db8f15e83b59d065dae62901138e5cb (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/zlib.c')
-rw-r--r-- | fs/btrfs/zlib.c | 26 |
1 files changed, 13 insertions, 13 deletions
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; |
301 | done: | 301 | done: |
@@ -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 | ||