Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752709AbbHGKkn (ORCPT ); Fri, 7 Aug 2015 06:40:43 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:37571 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751481AbbHGKkl (ORCPT ); Fri, 7 Aug 2015 06:40:41 -0400 X-AuditID: cbfee61b-f79706d000001b96-45-55c48b2874da From: Chao Yu To: Jaegeuk Kim , Yunlei He Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 2/4] f2fs: report EINVAL for unalignment direct IO Date: Fri, 07 Aug 2015 18:39:32 +0800 Message-id: <017f01d0d0fd$7f0917b0$7d1b4710$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AdDQ/A5zYUo0R5n0QRuyqS58iuivlQ== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrFLMWRmVeSWpSXmKPExsVy+t9jAV2N7iOhBtcm8VtsPR5j8WT9LGaL S4vcLfbsPclicXnXHDYHVo+WI29ZPTat6mTz2L3gM5PH501yASxRXDYpqTmZZalF+nYJXBmz nq1iL/gnVrFhz0eWBsbNQl2MnBwSAiYS06euZYKwxSQu3FvP1sXIxSEksJRR4sXyo6wQzitG iXcHOthAqtgEVCSWd/wH6xARcJWY3tfBDGIzC2RKTNg/nwXEFhZwkrgzfSWYzSKgKnG4dxU7 iM0rYCnx5t43VghbUOLH5HssEL1aEut3HmeCsOUlNq95ywxxkYLEjrOvGSF26Uk8fNXNCFEj LrHxyC2WCYwCs5CMmoVk1Cwko2YhaVnAyLKKUSK1ILmgOCk91ygvtVyvODG3uDQvXS85P3cT IzjEn0nvYDy8y/0QowAHoxIPb8K/w6FCrIllxZW5hxglOJiVRHjPVh8JFeJNSaysSi3Kjy8q zUktPsQozcGiJM6rb7IpVEggPbEkNTs1tSC1CCbLxMEp1cDI91dG575vZbJ3iNd7H8PQdUtk dsTJhk7atcWUf9qX+7PvLA0tf+er7qLomGm1b0HZFRZm37vrXVmuqD56eFXG7dXCPQoMXkcX THhaYOYsxvqsdMkb3agpqSdWKHy8mSW4lW9/7pzjh15Pmree4yLfo89CMyK2++8/Vf7YT3bD LX9xGS1+W8NAJZbijERDLeai4kQARDPKGW0CAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3094 Lines: 99 Hi all This patch is submitted by Yunlei He originally, but it's not complete one, so I modified it and add some description, then resubmit it. >From 3f8de7fe93354215b9b12293302a0a999cf3888a Mon Sep 17 00:00:00 2001 From: Yunlei He Date: Wed, 29 Jul 2015 15:10:24 +0800 Subject: [PATCH 2/4] f2fs: report EINVAL for unalignment direct IO We run ltp testcase with f2fs and obtain a TFAIL in diotest4, the result in detail is as fallow: dio04 <<>> tag=dio04 stime=1432278894 cmdline="diotest4" contacts="" analysis=exit <<>> diotest4 1 TPASS : Negative Offset diotest4 2 TPASS : removed diotest4 3 TFAIL : diotest4.c:129: write allows odd count.returns 1: Success diotest4 4 TFAIL : diotest4.c:183: Odd count of read and write diotest4 5 TPASS : Read beyond the file size ...... the result of ext4 with same environment: dio04 <<>> tag=dio04 stime=1432259643 cmdline="diotest4" contacts="" analysis=exit <<>> diotest4 1 TPASS : Negative Offset diotest4 2 TPASS : removed diotest4 3 TPASS : Odd count of read and write diotest4 4 TPASS : Read beyond the file size ...... The reason is that when triggering DIO in f2fs, we will return zero value in ->direct_IO if writer's buffer offset, file offset and transfer size is not alignment to block size of filesystem, resulting in falling back into buffered write instead of returning -EINVAL. This patch fixes that problem by returning correct error number for above case, and removing the judgement condition in check_direct_IO to make sure the verification will be enabled for direct reader too. Besides, Jaegeuk Kim pointed out that there is expectional cases we should always make direct-io falling back into buffered write, such as dio in encrypted file. Signed-off-by: Yunlei He [Chao Yu make small change and add detail description in commit message] Signed-off-by: Chao Yu --- fs/f2fs/data.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 4fabdd4..7ea8eda 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1494,9 +1494,6 @@ static int check_direct_IO(struct inode *inode, struct iov_iter *iter, { unsigned blocksize_mask = inode->i_sb->s_blocksize - 1; - if (iov_iter_rw(iter) == READ) - return 0; - if (offset & blocksize_mask) return -EINVAL; @@ -1525,8 +1522,9 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter, if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) return 0; - if (check_direct_IO(inode, iter, offset)) - return 0; + err = check_direct_IO(inode, iter, offset); + if (err) + return err; trace_f2fs_direct_IO_enter(inode, offset, count, iov_iter_rw(iter)); -- 2.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/