Commit d62e74be authored by Younger Liu's avatar Younger Liu Committed by Linus Torvalds

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: default avatarYounger Liu <younger.liu@huawei.com>
Reviewed-by: default avatarJie Liu <jeff.liu@oracle.com>
Tested-by: default avatarJie Liu <jeff.liu@oracle.com>
Cc: Joel Becker <jlbec@evilplan.org>
Reviewed-by: default avatarMark Fasheh <mfasheh@suse.de>
Cc: Sunil Mushran <sunil.mushran@gmail.com>
Reviewed-by: default avatarJensen <shencanquan@huawei.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8d547ff4
...@@ -7158,7 +7158,7 @@ int ocfs2_truncate_inline(struct inode *inode, struct buffer_head *di_bh, ...@@ -7158,7 +7158,7 @@ int ocfs2_truncate_inline(struct inode *inode, struct buffer_head *di_bh,
if (end > i_size_read(inode)) if (end > i_size_read(inode))
end = i_size_read(inode); end = i_size_read(inode);
BUG_ON(start >= end); BUG_ON(start > end);
if (!(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) || if (!(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) ||
!(le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_DATA_FL) || !(le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_DATA_FL) ||
......
...@@ -477,11 +477,6 @@ static int ocfs2_truncate_file(struct inode *inode, ...@@ -477,11 +477,6 @@ static int ocfs2_truncate_file(struct inode *inode,
goto bail; goto bail;
} }
/* lets handle the simple truncate cases before doing any more
* cluster locking. */
if (new_i_size == le64_to_cpu(fe->i_size))
goto bail;
down_write(&OCFS2_I(inode)->ip_alloc_sem); down_write(&OCFS2_I(inode)->ip_alloc_sem);
ocfs2_resv_discard(&osb->osb_la_resmap, ocfs2_resv_discard(&osb->osb_la_resmap,
...@@ -1148,14 +1143,14 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -1148,14 +1143,14 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
goto bail_unlock_rw; goto bail_unlock_rw;
} }
if (size_change && attr->ia_size != i_size_read(inode)) { if (size_change) {
status = inode_newsize_ok(inode, attr->ia_size); status = inode_newsize_ok(inode, attr->ia_size);
if (status) if (status)
goto bail_unlock; goto bail_unlock;
inode_dio_wait(inode); inode_dio_wait(inode);
if (i_size_read(inode) > attr->ia_size) { if (i_size_read(inode) >= attr->ia_size) {
if (ocfs2_should_order_data(inode)) { if (ocfs2_should_order_data(inode)) {
status = ocfs2_begin_ordered_truncate(inode, status = ocfs2_begin_ordered_truncate(inode,
attr->ia_size); attr->ia_size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment