Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocfs2: fix issue that ocfs2_setattr() does not deal with new_i_size==i_size

The issue scenario is as following:

- Create a small file and fallocate a large disk space for a file with
FALLOC_FL_KEEP_SIZE option.

- ftruncate the file back to the original size again. but the disk free
space is not changed back. This is a real bug that be fixed in this
patch.

In order to solve the issue above, we modified ocfs2_setattr(), if
attr->ia_size != i_size_read(inode), It calls ocfs2_truncate_file(), and
truncate disk space to attr->ia_size.

Signed-off-by: Younger Liu <younger.liu@huawei.com>
Reviewed-by: Jie Liu <jeff.liu@oracle.com>
Tested-by: Jie Liu <jeff.liu@oracle.com>
Cc: Joel Becker <jlbec@evilplan.org>
Reviewed-by: Mark Fasheh <mfasheh@suse.de>
Cc: Sunil Mushran <sunil.mushran@gmail.com>
Reviewed-by: Jensen <shencanquan@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Younger Liu and committed by
Linus Torvalds
d62e74be 8d547ff4

+3 -8
+1 -1
fs/ocfs2/alloc.c
··· 7158 7158 if (end > i_size_read(inode)) 7159 7159 end = i_size_read(inode); 7160 7160 7161 - BUG_ON(start >= end); 7161 + BUG_ON(start > end); 7162 7162 7163 7163 if (!(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) || 7164 7164 !(le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_DATA_FL) ||
+2 -7
fs/ocfs2/file.c
··· 477 477 goto bail; 478 478 } 479 479 480 - /* lets handle the simple truncate cases before doing any more 481 - * cluster locking. */ 482 - if (new_i_size == le64_to_cpu(fe->i_size)) 483 - goto bail; 484 - 485 480 down_write(&OCFS2_I(inode)->ip_alloc_sem); 486 481 487 482 ocfs2_resv_discard(&osb->osb_la_resmap, ··· 1143 1148 goto bail_unlock_rw; 1144 1149 } 1145 1150 1146 - if (size_change && attr->ia_size != i_size_read(inode)) { 1151 + if (size_change) { 1147 1152 status = inode_newsize_ok(inode, attr->ia_size); 1148 1153 if (status) 1149 1154 goto bail_unlock; 1150 1155 1151 1156 inode_dio_wait(inode); 1152 1157 1153 - if (i_size_read(inode) > attr->ia_size) { 1158 + if (i_size_read(inode) >= attr->ia_size) { 1154 1159 if (ocfs2_should_order_data(inode)) { 1155 1160 status = ocfs2_begin_ordered_truncate(inode, 1156 1161 attr->ia_size);