Commit f76ddff6c5215131483efed20acc896e021abb9f

Authored by Liu Bo
Committed by Greg Kroah-Hartman
1 parent 49fc90b443

Btrfs: adjust outstanding_extents counter properly when dio write is split

[ Upstream commit c2931667c83ded6504b3857e99cc45b21fa496fb ]

Currently how btrfs dio deals with split dio write is not good
enough if dio write is split into several segments due to the
lack of contiguous space, a large dio write like 'dd bs=1G count=1'
can end up with incorrect outstanding_extents counter and endio
would complain loudly with an assertion.

This fixes the problem by compensating the outstanding_extents
counter in inode if a large dio write gets split.

Reported-by: Anand Jain <anand.jain@oracle.com>
Tested-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 9 additions and 2 deletions Side-by-side Diff

... ... @@ -7648,11 +7648,18 @@
7648 7648 * within our reservation, otherwise we need to adjust our inode
7649 7649 * counter appropriately.
7650 7650 */
7651   - if (dio_data->outstanding_extents) {
  7651 + if (dio_data->outstanding_extents >= num_extents) {
7652 7652 dio_data->outstanding_extents -= num_extents;
7653 7653 } else {
  7654 + /*
  7655 + * If dio write length has been split due to no large enough
  7656 + * contiguous space, we need to compensate our inode counter
  7657 + * appropriately.
  7658 + */
  7659 + u64 num_needed = num_extents - dio_data->outstanding_extents;
  7660 +
7654 7661 spin_lock(&BTRFS_I(inode)->lock);
7655   - BTRFS_I(inode)->outstanding_extents += num_extents;
  7662 + BTRFS_I(inode)->outstanding_extents += num_needed;
7656 7663 spin_unlock(&BTRFS_I(inode)->lock);
7657 7664 }
7658 7665 }