ocfs2: fix issue that ocfs2_setattr() does not deal with new_i_size==i_size
authorYounger Liu <younger.liu@huawei.com>
Mon, 10 Feb 2014 22:25:51 +0000 (14:25 -0800)
committerBen Hutchings <ben@decadent.org.uk>
Tue, 13 Feb 2018 18:32:16 +0000 (18:32 +0000)
commitd885f08eabd0c9e920960b52d1cc17a4e9393e88
tree0f3412e0bafcfe31ce2bc1ef870b3e79ad70b0bd
parent999b8ffebb07896df897b4cfd5b237f10482be05
ocfs2: fix issue that ocfs2_setattr() does not deal with new_i_size==i_size

commit d62e74be1270c89fbaf7aada8218bfdf62d00a58 upstream.

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>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/ocfs2/alloc.c
fs/ocfs2/file.c