* Given an address space and start and length, compress the bytes into @pages
* that are allocated on demand.
*
- * @out_pages is used to return the number of pages allocated. There
- * may be pages allocated even if we return an error.
+ * @out_pages is an in/out parameter, holds maximum number of pages to allocate
+ * and returns number of actually allocated pages
*
* @total_in is used to return the number of bytes actually read. It
* may be smaller than the input length if we had to exit early because we
*/
int btrfs_compress_pages(int type, struct address_space *mapping,
u64 start, struct page **pages,
- unsigned long nr_dest_pages,
unsigned long *out_pages,
unsigned long *total_in,
unsigned long *total_out,
ret = btrfs_compress_op[type-1]->compress_pages(workspace, mapping,
start, pages,
- nr_dest_pages, out_pages,
+ out_pages,
total_in, total_out,
max_out);
free_workspace(type, workspace);
int btrfs_compress_pages(int type, struct address_space *mapping,
u64 start, struct page **pages,
- unsigned long nr_dest_pages,
unsigned long *out_pages,
unsigned long *total_in,
unsigned long *total_out,
struct address_space *mapping,
u64 start,
struct page **pages,
- unsigned long nr_dest_pages,
unsigned long *out_pages,
unsigned long *total_in,
unsigned long *total_out,
int ret = 0;
struct page **pages = NULL;
unsigned long nr_pages;
- unsigned long nr_pages_ret = 0;
unsigned long total_compressed = 0;
unsigned long total_in = 0;
unsigned long max_compressed = SZ_128K;
ret = btrfs_compress_pages(compress_type,
inode->i_mapping, start,
pages,
- nr_pages, &nr_pages_ret,
+ &nr_pages,
&total_in,
&total_compressed,
max_compressed);
if (!ret) {
unsigned long offset = total_compressed &
(PAGE_SIZE - 1);
- struct page *page = pages[nr_pages_ret - 1];
+ struct page *page = pages[nr_pages - 1];
char *kaddr;
/* zero the tail end of the last page, we might be
* will submit them to the elevator.
*/
add_async_extent(async_cow, start, num_bytes,
- total_compressed, pages, nr_pages_ret,
+ total_compressed, pages, nr_pages,
compress_type);
if (start + num_bytes < end) {
* the compression code ran but failed to make things smaller,
* free any pages it allocated and our page pointer array
*/
- for (i = 0; i < nr_pages_ret; i++) {
+ for (i = 0; i < nr_pages; i++) {
WARN_ON(pages[i]->mapping);
put_page(pages[i]);
}
kfree(pages);
pages = NULL;
total_compressed = 0;
- nr_pages_ret = 0;
+ nr_pages = 0;
/* flag the file so we don't compress in the future */
if (!btrfs_test_opt(fs_info, FORCE_COMPRESS) &&
return;
free_pages_out:
- for (i = 0; i < nr_pages_ret; i++) {
+ for (i = 0; i < nr_pages; i++) {
WARN_ON(pages[i]->mapping);
put_page(pages[i]);
}
struct address_space *mapping,
u64 start,
struct page **pages,
- unsigned long nr_dest_pages,
unsigned long *out_pages,
unsigned long *total_in,
unsigned long *total_out,
struct page *out_page = NULL;
unsigned long bytes_left;
unsigned long len = *total_out;
+ unsigned long nr_dest_pages = *out_pages;
size_t in_len;
size_t out_len;
char *buf;
struct address_space *mapping,
u64 start,
struct page **pages,
- unsigned long nr_dest_pages,
unsigned long *out_pages,
unsigned long *total_in,
unsigned long *total_out,
struct page *out_page = NULL;
unsigned long bytes_left;
unsigned long len = *total_out;
+ unsigned long nr_dest_pages = *out_pages;
*out_pages = 0;
*total_out = 0;