Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932428AbbFIC2r (ORCPT ); Mon, 8 Jun 2015 22:28:47 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:51270 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932306AbbFIC2j (ORCPT ); Mon, 8 Jun 2015 22:28:39 -0400 X-AuditID: cbfee61a-f79516d000006302-0f-55764f56a6af From: Chao Yu To: Jaegeuk Kim , Changman Lee Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v2] f2fs: do not trim preallocated blocks when truncating after i_size Date: Tue, 09 Jun 2015 10:27:39 +0800 Message-id: <007b01d0a25b$ff2a99d0$fd7fcd70$@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: AdCiW9sD4MzpIUwKQqSfVN11SFHinQ== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrMLMWRmVeSWpSXmKPExsVy+t9jQd0w/7JQg8/z+S2u7Wtksniyfhaz xaVF7haXd81hc2Dx2LSqk81j94LPTB59W1YxenzeJBfAEsVlk5Kak1mWWqRvl8CVMW3rOaaC lXwVF8+2MDUwTuPuYuTkkBAwkZhy+x4jhC0mceHeerYuRi4OIYHpjBJ/T/9lhXBeMUqc+9zP AlLFJqAisbzjPxOILSLgJTFp/wmwOLOAh0Rjx3dWEFtYIEJi9o4GsBoWAVWJD1M+gMV5BSwl Xs54ygJhC0r8mHwPqldLYv3O40wQtrzE5jVvmSEuUpDYcfY1I8QuPYk76xazQdSIS2w8cotl AqPALCSjZiEZNQvJqFlIWhYwsqxiFE0tSC4oTkrPNdQrTswtLs1L10vOz93ECA7qZ1I7GFc2 WBxiFOBgVOLhVVAuCxViTSwrrsw9xCjBwawkwlvIChTiTUmsrEotyo8vKs1JLT7EKM3BoiTO ezLfJ1RIID2xJDU7NbUgtQgmy8TBKdXAaD/LeuvFNX2ny5kfXS967MDWI6S/8ZLKeTunpdGJ rwMUOrYt7ZP5onju6Pctp70yHT8zKGTrnTonKSU1sUCetXej1aUr5zUkE8zeL5dcZjKVc777 6ajDXxf//nDjwAmVXbc+WBuF/FnaFW/i8G5StJtt7JuqeUavlzklFZzVPGw6fWnePYX3+Uos xRmJhlrMRcWJAFREGhFmAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2015 Lines: 68 When we perform generic/092 in xfstests, output is like below: XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 0: [0..10239]: data 0: [0..10239]: data -1: [10240..20479]: unwritten +1: [10240..14335]: unwritten This is because with this testcase, we redefine the regulation for truncate in perallocated space past i_size as below: "There was some confused about what the fs was supposed to do when you truncate at i_size with preallocated space past i_size. We decided on the following things. 1) truncate(i_size) will trim all blocks past i_size. 2) truncate(x) where x > i_size will not trim all blocks past i_size. " This method is used in xfs, and then ext4/btrfs will follow the rule. This patch fixes to follow the new rule for f2fs. Signed-off-by: Chao Yu --- v2: * adjust code style pointed out by Jaegeuk Kim. fs/f2fs/file.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 4d42d66..ec47c4a 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -651,16 +651,15 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) f2fs_get_encryption_info(inode)) return -EACCES; - if (attr->ia_size != i_size_read(inode)) { - truncate_setsize(inode, attr->ia_size); + truncate_setsize(inode, attr->ia_size); + + /* + * do not trim all preallocated blocks after i_size if target + * size is larger than i_size. + */ + if (attr->ia_size <= i_size_read(inode)) { f2fs_truncate(inode); f2fs_balance_fs(F2FS_I_SB(inode)); - } else { - /* - * giving a chance to truncate blocks past EOF which - * are fallocated with FALLOC_FL_KEEP_SIZE. - */ - f2fs_truncate(inode); } } -- 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/