Skip to content

Commit d62e74b

Browse files
Younger Liutorvalds
authored andcommitted
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 <[email protected]> Reviewed-by: Jie Liu <[email protected]> Tested-by: Jie Liu <[email protected]> Cc: Joel Becker <[email protected]> Reviewed-by: Mark Fasheh <[email protected]> Cc: Sunil Mushran <[email protected]> Reviewed-by: Jensen <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 8d547ff commit d62e74b

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

fs/ocfs2/alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7158,7 +7158,7 @@ int ocfs2_truncate_inline(struct inode *inode, struct buffer_head *di_bh,
71587158
if (end > i_size_read(inode))
71597159
end = i_size_read(inode);
71607160

7161-
BUG_ON(start >= end);
7161+
BUG_ON(start > end);
71627162

71637163
if (!(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) ||
71647164
!(le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_DATA_FL) ||

fs/ocfs2/file.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,6 @@ static int ocfs2_truncate_file(struct inode *inode,
477477
goto bail;
478478
}
479479

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-
485480
down_write(&OCFS2_I(inode)->ip_alloc_sem);
486481

487482
ocfs2_resv_discard(&osb->osb_la_resmap,
@@ -1148,14 +1143,14 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
11481143
goto bail_unlock_rw;
11491144
}
11501145

1151-
if (size_change && attr->ia_size != i_size_read(inode)) {
1146+
if (size_change) {
11521147
status = inode_newsize_ok(inode, attr->ia_size);
11531148
if (status)
11541149
goto bail_unlock;
11551150

11561151
inode_dio_wait(inode);
11571152

1158-
if (i_size_read(inode) > attr->ia_size) {
1153+
if (i_size_read(inode) >= attr->ia_size) {
11591154
if (ocfs2_should_order_data(inode)) {
11601155
status = ocfs2_begin_ordered_truncate(inode,
11611156
attr->ia_size);

0 commit comments

Comments
 (0)