Re: [PATCH v5 9/9] btrfs: implement RWF_ENCODED writes

Josef Bacik
2020-08-24T20:31:01Z

On 8/21/20 3:38 AM, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
>
> The implementation resembles direct I/O: we have to flush any ordered
> extents, invalidate the page cache, and do the io tree/delalloc/extent
> map/ordered extent dance. From there, we can reuse the compression code
> with a minor modification to distinguish the write from writeback. This
> also creates inline extents when possible.
>
> Now that read and write are implemented, this also sets the
> FMODE_ENCODED_IO flag in btrfs_file_open().
>
> Signed-off-by: Omar Sandoval <osandov@fb.com>
> ---
> fs/btrfs/compression.c | 7 +-
> fs/btrfs/compression.h | 6 +-
> fs/btrfs/ctree.h | 2 +
> fs/btrfs/file.c | 40 +++++--
> fs/btrfs/inode.c | 246 +++++++++++++++++++++++++++++++++++++++-
> fs/btrfs/ordered-data.c | 12 +-
> fs/btrfs/ordered-data.h | 2 +
> 7 files changed, 298 insertions(+), 17 deletions(-)
>

<snip>

> +
> + ret = btrfs_alloc_data_chunk_ondemand(BTRFS_I(inode), disk_num_bytes);
> + if (ret)
> + goto out_unlock;
> + ret = btrfs_qgroup_reserve_data(BTRFS_I(inode), &data_reserved, start,
> + num_bytes);
> + if (ret)
> + goto out_free_data_space;
> + ret = btrfs_delalloc_reserve_metadata(BTRFS_I(inode), num_bytes,
> + disk_num_bytes);
> + if (ret)
> + goto out_qgroup_free_data;

This can just be btrfs_delalloc_reserve_space() and that way the error handling
is much cleaner.

<snip>
> +
> +out_free_reserved:
> + btrfs_dec_block_group_reservations(fs_info, ins.objectid);
> + btrfs_free_reserved_extent(fs_info, ins.objectid, ins.offset, 1);
> +out_delalloc_release:
> + btrfs_delalloc_release_extents(BTRFS_I(inode), num_bytes);
> + btrfs_delalloc_release_metadata(BTRFS_I(inode), disk_num_bytes,
> + ret < 0);

Likewise this can all just be btrfs_free_reserved_data_space(). Thanks,

Josef