Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755976AbdDFMDN (ORCPT ); Thu, 6 Apr 2017 08:03:13 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:35637 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755799AbdDFMDA (ORCPT ); Thu, 6 Apr 2017 08:03:00 -0400 From: Dmitry Monakhov To: linux-kernel@vger.kernel.org Cc: darrick.wong@oracle.com, axboe@kernel.dk, tytso@mit.edu, jack@suse.cz, hch@infradead.org, Dmitry Monakhov Subject: [PATCH 5/5] block: truncate page cache only when necessary on fallocate Date: Thu, 6 Apr 2017 16:02:49 +0400 Message-Id: <1491480169-1889-6-git-send-email-dmonakhov@openvz.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1491480169-1889-1-git-send-email-dmonakhov@openvz.org> References: <1491480169-1889-1-git-send-email-dmonakhov@openvz.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1875 Lines: 50 Signed-off-by: Dmitry Monakhov --- fs/block_dev.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index 2eca00e..f4b13e1 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -2075,7 +2075,7 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start, { struct block_device *bdev = I_BDEV(bdev_file_inode(file)); struct request_queue *q = bdev_get_queue(bdev); - struct address_space *mapping; + struct address_space *mapping = bdev->bd_inode->i_mapping; loff_t end = start + len - 1; loff_t isize; int error; @@ -2102,13 +2102,10 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start, if ((start | len) & (bdev_logical_block_size(bdev) - 1)) return -EINVAL; - /* Invalidate the page cache, including dirty pages. */ - mapping = bdev->bd_inode->i_mapping; - truncate_inode_pages_range(mapping, start, end); - switch (mode) { case FALLOC_FL_ZERO_RANGE: case FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE: + truncate_inode_pages_range(mapping, start, end); error = blkdev_issue_zeroout(bdev, start >> 9, len >> 9, GFP_KERNEL, false); break; @@ -2116,12 +2113,14 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start, /* Only punch if the device can do zeroing discard. */ if (!blk_queue_discard(q) || !q->limits.discard_zeroes_data) return -EOPNOTSUPP; + truncate_inode_pages_range(mapping, start, end); error = blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_KERNEL, 0); break; case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE | FALLOC_FL_NO_HIDE_STALE: if (!blk_queue_discard(q)) return -EOPNOTSUPP; + truncate_inode_pages_range(mapping, start, end); error = blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_KERNEL, 0); break; -- 2.9.3