Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac3e9933 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba
Browse files

btrfs: Return number of compressed extents directly in compress_file_range



compress_file_range returns a void, yet uses a function parameter as a
return value. Make that more idiomatic by simply returning the number
of compressed extents directly. Also track such extents in more aptly
named variables. No functional changes.

Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 40cf931f
Loading
Loading
Loading
Loading
+11 −9
Original line number Original line Diff line number Diff line
@@ -462,8 +462,7 @@ static inline void inode_should_defrag(struct btrfs_inode *inode,
 * are written in the same order that the flusher thread sent them
 * are written in the same order that the flusher thread sent them
 * down.
 * down.
 */
 */
static noinline void compress_file_range(struct async_chunk *async_chunk,
static noinline int compress_file_range(struct async_chunk *async_chunk)
					 int *num_added)
{
{
	struct inode *inode = async_chunk->inode;
	struct inode *inode = async_chunk->inode;
	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
@@ -479,6 +478,7 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
	int i;
	int i;
	int will_compress;
	int will_compress;
	int compress_type = fs_info->compress_type;
	int compress_type = fs_info->compress_type;
	int compressed_extents = 0;
	int redirty = 0;
	int redirty = 0;


	inode_should_defrag(BTRFS_I(inode), start, end, end - start + 1,
	inode_should_defrag(BTRFS_I(inode), start, end, end - start + 1,
@@ -641,7 +641,7 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
		 */
		 */
		total_in = ALIGN(total_in, PAGE_SIZE);
		total_in = ALIGN(total_in, PAGE_SIZE);
		if (total_compressed + blocksize <= total_in) {
		if (total_compressed + blocksize <= total_in) {
			*num_added += 1;
			compressed_extents++;


			/*
			/*
			 * The async work queues will take care of doing actual
			 * The async work queues will take care of doing actual
@@ -658,7 +658,7 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
				cond_resched();
				cond_resched();
				goto again;
				goto again;
			}
			}
			return;
			return compressed_extents;
		}
		}
	}
	}
	if (pages) {
	if (pages) {
@@ -697,9 +697,9 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
		extent_range_redirty_for_io(inode, start, end);
		extent_range_redirty_for_io(inode, start, end);
	add_async_extent(async_chunk, start, end - start + 1, 0, NULL, 0,
	add_async_extent(async_chunk, start, end - start + 1, 0, NULL, 0,
			 BTRFS_COMPRESS_NONE);
			 BTRFS_COMPRESS_NONE);
	*num_added += 1;
	compressed_extents++;


	return;
	return compressed_extents;


free_pages_out:
free_pages_out:
	for (i = 0; i < nr_pages; i++) {
	for (i = 0; i < nr_pages; i++) {
@@ -707,6 +707,8 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
		put_page(pages[i]);
		put_page(pages[i]);
	}
	}
	kfree(pages);
	kfree(pages);

	return 0;
}
}


static void free_async_extent_pages(struct async_extent *async_extent)
static void free_async_extent_pages(struct async_extent *async_extent)
@@ -1144,12 +1146,12 @@ static noinline int cow_file_range(struct inode *inode,
static noinline void async_cow_start(struct btrfs_work *work)
static noinline void async_cow_start(struct btrfs_work *work)
{
{
	struct async_chunk *async_chunk;
	struct async_chunk *async_chunk;
	int num_added = 0;
	int compressed_extents;


	async_chunk = container_of(work, struct async_chunk, work);
	async_chunk = container_of(work, struct async_chunk, work);


	compress_file_range(async_chunk, &num_added);
	compressed_extents = compress_file_range(async_chunk);
	if (num_added == 0) {
	if (compressed_extents == 0) {
		btrfs_add_delayed_iput(async_chunk->inode);
		btrfs_add_delayed_iput(async_chunk->inode);
		async_chunk->inode = NULL;
		async_chunk->inode = NULL;
	}
	}