Skip to content

Commit

Permalink
btrfs: return errno instead of -1 from compression
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Zach Brown authored and Chris Mason committed Jun 10, 2014
1 parent 98806b4 commit 60e1975
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
14 changes: 7 additions & 7 deletions fs/btrfs/lzo.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static int lzo_compress_pages(struct list_head *ws,
if (ret != LZO_E_OK) {
printk(KERN_DEBUG "BTRFS: deflate in loop returned %d\n",
ret);
ret = -1;
ret = -EIO;
goto out;
}

Expand Down Expand Up @@ -189,7 +189,7 @@ static int lzo_compress_pages(struct list_head *ws,
kunmap(out_page);
if (nr_pages == nr_dest_pages) {
out_page = NULL;
ret = -1;
ret = -E2BIG;
goto out;
}

Expand All @@ -208,7 +208,7 @@ static int lzo_compress_pages(struct list_head *ws,

/* we're making it bigger, give up */
if (tot_in > 8192 && tot_in < tot_out) {
ret = -1;
ret = -E2BIG;
goto out;
}

Expand Down Expand Up @@ -335,7 +335,7 @@ static int lzo_decompress_biovec(struct list_head *ws,
break;

if (page_in_index + 1 >= total_pages_in) {
ret = -1;
ret = -EIO;
goto done;
}

Expand All @@ -358,7 +358,7 @@ static int lzo_decompress_biovec(struct list_head *ws,
kunmap(pages_in[page_in_index - 1]);
if (ret != LZO_E_OK) {
printk(KERN_WARNING "BTRFS: decompress failed\n");
ret = -1;
ret = -EIO;
break;
}

Expand Down Expand Up @@ -402,12 +402,12 @@ static int lzo_decompress(struct list_head *ws, unsigned char *data_in,
ret = lzo1x_decompress_safe(data_in, in_len, workspace->buf, &out_len);
if (ret != LZO_E_OK) {
printk(KERN_WARNING "BTRFS: decompress failed!\n");
ret = -1;
ret = -EIO;
goto out;
}

if (out_len < start_byte) {
ret = -1;
ret = -EIO;
goto out;
}

Expand Down
26 changes: 13 additions & 13 deletions fs/btrfs/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static int zlib_compress_pages(struct list_head *ws,

if (Z_OK != zlib_deflateInit(&workspace->def_strm, 3)) {
printk(KERN_WARNING "BTRFS: deflateInit failed\n");
ret = -1;
ret = -EIO;
goto out;
}

Expand All @@ -110,7 +110,7 @@ static int zlib_compress_pages(struct list_head *ws,

out_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM);
if (out_page == NULL) {
ret = -1;
ret = -ENOMEM;
goto out;
}
cpage_out = kmap(out_page);
Expand All @@ -128,15 +128,15 @@ static int zlib_compress_pages(struct list_head *ws,
printk(KERN_DEBUG "BTRFS: deflate in loop returned %d\n",
ret);
zlib_deflateEnd(&workspace->def_strm);
ret = -1;
ret = -EIO;
goto out;
}

/* we're making it bigger, give up */
if (workspace->def_strm.total_in > 8192 &&
workspace->def_strm.total_in <
workspace->def_strm.total_out) {
ret = -1;
ret = -EIO;
goto out;
}
/* we need another page for writing out. Test this
Expand All @@ -147,12 +147,12 @@ static int zlib_compress_pages(struct list_head *ws,
kunmap(out_page);
if (nr_pages == nr_dest_pages) {
out_page = NULL;
ret = -1;
ret = -E2BIG;
goto out;
}
out_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM);
if (out_page == NULL) {
ret = -1;
ret = -ENOMEM;
goto out;
}
cpage_out = kmap(out_page);
Expand Down Expand Up @@ -188,12 +188,12 @@ static int zlib_compress_pages(struct list_head *ws,
zlib_deflateEnd(&workspace->def_strm);

if (ret != Z_STREAM_END) {
ret = -1;
ret = -EIO;
goto out;
}

if (workspace->def_strm.total_out >= workspace->def_strm.total_in) {
ret = -1;
ret = -E2BIG;
goto out;
}

Expand Down Expand Up @@ -253,7 +253,7 @@ static int zlib_decompress_biovec(struct list_head *ws, struct page **pages_in,

if (Z_OK != zlib_inflateInit2(&workspace->inf_strm, wbits)) {
printk(KERN_WARNING "BTRFS: inflateInit failed\n");
return -1;
return -EIO;
}
while (workspace->inf_strm.total_in < srclen) {
ret = zlib_inflate(&workspace->inf_strm, Z_NO_FLUSH);
Expand Down Expand Up @@ -295,7 +295,7 @@ static int zlib_decompress_biovec(struct list_head *ws, struct page **pages_in,
}
}
if (ret != Z_STREAM_END)
ret = -1;
ret = -EIO;
else
ret = 0;
done:
Expand Down Expand Up @@ -337,7 +337,7 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in,

if (Z_OK != zlib_inflateInit2(&workspace->inf_strm, wbits)) {
printk(KERN_WARNING "BTRFS: inflateInit failed\n");
return -1;
return -EIO;
}

while (bytes_left > 0) {
Expand All @@ -354,7 +354,7 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in,
total_out = workspace->inf_strm.total_out;

if (total_out == buf_start) {
ret = -1;
ret = -EIO;
break;
}

Expand Down Expand Up @@ -382,7 +382,7 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in,
}

if (ret != Z_STREAM_END && bytes_left != 0)
ret = -1;
ret = -EIO;
else
ret = 0;

Expand Down

0 comments on commit 60e1975

Please sign in to comment.