• Naohiro Aota's avatar
    btrfs: zoned: write out partially allocated region · 898793d9
    Naohiro Aota authored
    cow_file_range() works in an all-or-nothing way: if it fails to allocate an
    extent for a part of the given region, it gives up all the region including
    the successfully allocated parts. On cow_file_range(), run_delalloc_zoned()
    writes data for the region only when it successfully allocate all the
    region.
    
    This all-or-nothing allocation and write-out are problematic when available
    space in all the block groups are get tight with the active zone
    restriction. btrfs_reserve_extent() try hard to utilize the left space in
    the active block groups and gives up finally and fails with
    -ENOSPC. However, if we send IOs for the successfully allocated region, we
    can finish a zone and can continue on the rest of the allocation on a newly
    allocated block group.
    
    This patch implements the partial write-out for run_delalloc_zoned(). With
    this patch applied, cow_file_range() returns -EAGAIN to tell the caller to
    do something to progress the further allocation, and tells the successfully
    allocated region with done_offset. Furthermore, the zoned extent allocator
    returns -EAGAIN to tell cow_file_range() going back to the caller side.
    
    Actually, we still need to wait for an IO to complete to continue the
    allocation. The next patch implements that part.
    
    CC: stable@vger.kernel.org # 5.16+
    Fixes: afba2bc0 ("btrfs: zoned: implement active zone tracking")
    Signed-off-by: default avatarNaohiro Aota <naohiro.aota@wdc.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    898793d9
inode.c 326 KB