Skip to content

Commit 786fd31

Browse files
Liu Bogregkh
authored andcommitted
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>
1 parent 7ea3cc4 commit 786fd31

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

fs/btrfs/inode.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7521,11 +7521,18 @@ static void adjust_dio_outstanding_extents(struct inode *inode,
75217521
* within our reservation, otherwise we need to adjust our inode
75227522
* counter appropriately.
75237523
*/
7524-
if (dio_data->outstanding_extents) {
7524+
if (dio_data->outstanding_extents >= num_extents) {
75257525
dio_data->outstanding_extents -= num_extents;
75267526
} else {
7527+
/*
7528+
* If dio write length has been split due to no large enough
7529+
* contiguous space, we need to compensate our inode counter
7530+
* appropriately.
7531+
*/
7532+
u64 num_needed = num_extents - dio_data->outstanding_extents;
7533+
75277534
spin_lock(&BTRFS_I(inode)->lock);
7528-
BTRFS_I(inode)->outstanding_extents += num_extents;
7535+
BTRFS_I(inode)->outstanding_extents += num_needed;
75297536
spin_unlock(&BTRFS_I(inode)->lock);
75307537
}
75317538
}

0 commit comments

Comments
 (0)