diff options
author | Liu Bo <bo.li.liu@oracle.com> | 2016-12-22 17:13:54 -0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-08-06 18:59:47 -0700 |
commit | f76ddff6c5215131483efed20acc896e021abb9f (patch) | |
tree | 54705f2208d369bd32e0ef9da908f44f80562991 /fs/btrfs | |
parent | 49fc90b443c71b3cdbfaf15c0c15fc7e3ffc5731 (diff) | |
download | linux-stable-f76ddff6c5215131483efed20acc896e021abb9f.tar.gz linux-stable-f76ddff6c5215131483efed20acc896e021abb9f.tar.bz2 linux-stable-f76ddff6c5215131483efed20acc896e021abb9f.zip |
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>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/inode.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index a2a014b19f18..8a05fa7e2152 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7648,11 +7648,18 @@ static void adjust_dio_outstanding_extents(struct inode *inode, * within our reservation, otherwise we need to adjust our inode * counter appropriately. */ - if (dio_data->outstanding_extents) { + if (dio_data->outstanding_extents >= num_extents) { dio_data->outstanding_extents -= num_extents; } else { + /* + * If dio write length has been split due to no large enough + * contiguous space, we need to compensate our inode counter + * appropriately. + */ + u64 num_needed = num_extents - dio_data->outstanding_extents; + spin_lock(&BTRFS_I(inode)->lock); - BTRFS_I(inode)->outstanding_extents += num_extents; + BTRFS_I(inode)->outstanding_extents += num_needed; spin_unlock(&BTRFS_I(inode)->lock); } } |