Skip to content

Commit 60e1975

Browse files
Zach Brownmasoncl
authored andcommitted
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 <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent 98806b4 commit 60e1975

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

fs/btrfs/lzo.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static int lzo_compress_pages(struct list_head *ws,
143143
if (ret != LZO_E_OK) {
144144
printk(KERN_DEBUG "BTRFS: deflate in loop returned %d\n",
145145
ret);
146-
ret = -1;
146+
ret = -EIO;
147147
goto out;
148148
}
149149

@@ -189,7 +189,7 @@ static int lzo_compress_pages(struct list_head *ws,
189189
kunmap(out_page);
190190
if (nr_pages == nr_dest_pages) {
191191
out_page = NULL;
192-
ret = -1;
192+
ret = -E2BIG;
193193
goto out;
194194
}
195195

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

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

@@ -335,7 +335,7 @@ static int lzo_decompress_biovec(struct list_head *ws,
335335
break;
336336

337337
if (page_in_index + 1 >= total_pages_in) {
338-
ret = -1;
338+
ret = -EIO;
339339
goto done;
340340
}
341341

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

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

409409
if (out_len < start_byte) {
410-
ret = -1;
410+
ret = -EIO;
411411
goto out;
412412
}
413413

fs/btrfs/zlib.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static int zlib_compress_pages(struct list_head *ws,
9898

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

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

111111
out_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM);
112112
if (out_page == NULL) {
113-
ret = -1;
113+
ret = -ENOMEM;
114114
goto out;
115115
}
116116
cpage_out = kmap(out_page);
@@ -128,15 +128,15 @@ static int zlib_compress_pages(struct list_head *ws,
128128
printk(KERN_DEBUG "BTRFS: deflate in loop returned %d\n",
129129
ret);
130130
zlib_deflateEnd(&workspace->def_strm);
131-
ret = -1;
131+
ret = -EIO;
132132
goto out;
133133
}
134134

135135
/* we're making it bigger, give up */
136136
if (workspace->def_strm.total_in > 8192 &&
137137
workspace->def_strm.total_in <
138138
workspace->def_strm.total_out) {
139-
ret = -1;
139+
ret = -EIO;
140140
goto out;
141141
}
142142
/* we need another page for writing out. Test this
@@ -147,12 +147,12 @@ static int zlib_compress_pages(struct list_head *ws,
147147
kunmap(out_page);
148148
if (nr_pages == nr_dest_pages) {
149149
out_page = NULL;
150-
ret = -1;
150+
ret = -E2BIG;
151151
goto out;
152152
}
153153
out_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM);
154154
if (out_page == NULL) {
155-
ret = -1;
155+
ret = -ENOMEM;
156156
goto out;
157157
}
158158
cpage_out = kmap(out_page);
@@ -188,12 +188,12 @@ static int zlib_compress_pages(struct list_head *ws,
188188
zlib_deflateEnd(&workspace->def_strm);
189189

190190
if (ret != Z_STREAM_END) {
191-
ret = -1;
191+
ret = -EIO;
192192
goto out;
193193
}
194194

195195
if (workspace->def_strm.total_out >= workspace->def_strm.total_in) {
196-
ret = -1;
196+
ret = -E2BIG;
197197
goto out;
198198
}
199199

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

254254
if (Z_OK != zlib_inflateInit2(&workspace->inf_strm, wbits)) {
255255
printk(KERN_WARNING "BTRFS: inflateInit failed\n");
256-
return -1;
256+
return -EIO;
257257
}
258258
while (workspace->inf_strm.total_in < srclen) {
259259
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,
295295
}
296296
}
297297
if (ret != Z_STREAM_END)
298-
ret = -1;
298+
ret = -EIO;
299299
else
300300
ret = 0;
301301
done:
@@ -337,7 +337,7 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in,
337337

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

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

356356
if (total_out == buf_start) {
357-
ret = -1;
357+
ret = -EIO;
358358
break;
359359
}
360360

@@ -382,7 +382,7 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in,
382382
}
383383

384384
if (ret != Z_STREAM_END && bytes_left != 0)
385-
ret = -1;
385+
ret = -EIO;
386386
else
387387
ret = 0;
388388

0 commit comments

Comments
 (0)