From: Jeff Liu <jeff.liu@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] btrfs: fix file truncation if FALLOC_FL_KEEP_SIZE is specified
Date: Fri, 28 Jun 2013 13:15:52 +0800 [thread overview]
Message-ID: <51CD1C08.40801@oracle.com> (raw)
From: Jie Liu <jeff.liu@oracle.com>
Create a small file and fallocate it to a big size with
FALLOC_FL_KEEP_SIZE option, then truncate it back to the
small size again, the disk free space is not changed back
in this case. i.e,
# dd if=/dev/zero of=/mnt/test bs=512 count=1
# ls -l /mnt
total 4
-rw-r--r-- 1 root root 512 Jun 28 11:35 test
# df -h
Filesystem Size Used Avail Use% Mounted on
....
/dev/sdb1 8.0G 56K 7.2G 1% /mnt
# xfs_io -c 'falloc -k 512 5G' /mnt/test
# ls -l /mnt/test
-rw-r--r-- 1 root root 512 Jun 28 11:35 /mnt/test
# sync; df -h
Filesystem Size Used Avail Use% Mounted on
....
/dev/sdb1 8.0G 5.1G 2.2G 70% /mnt
# xfs_io -c 'truncate 512' /mnt/test
# sync; df -h
Filesystem Size Used Avail Use% Mounted on
....
/dev/sdb1 8.0G 5.1G 2.2G 70% /mnt
With this fix, the truncated up space is back as:
# sync; df -h
Filesystem Size Used Avail Use% Mounted on
....
/dev/sdb1 8.0G 56K 7.2G 1% /mnt
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
---
fs/btrfs/inode.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 4f9d16b..7e1a5ff 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4509,9 +4509,6 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
int mask = attr->ia_valid;
int ret;
- if (newsize == oldsize)
- return 0;
-
/*
* The regular truncate() case without ATTR_CTIME and ATTR_MTIME is a
* special case where we need to update the times despite not having
--
1.7.9.5
next reply other threads:[~2013-06-28 5:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-28 5:15 Jeff Liu [this message]
2013-06-28 12:41 ` [PATCH] btrfs: fix file truncation if FALLOC_FL_KEEP_SIZE is specified Josef Bacik
2013-06-28 13:07 ` Jeff Liu
2013-06-28 13:12 ` Josef Bacik
2013-06-29 2:22 ` Dave Chinner
2013-06-29 2:44 ` Jeff Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51CD1C08.40801@oracle.com \
--to=jeff.liu@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.