diff options
author | Liu Bo <bo.li.liu@oracle.com> | 2016-12-01 13:01:02 -0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2017-02-14 15:50:57 +0100 |
commit | 19fd2df5b1167eeb6ae8912cdfe9532e3b2c8bbe (patch) | |
tree | 10c1a429ce6b3c8d4ca97c54bcf11856db51cc86 /fs/btrfs/inode.c | |
parent | f85b7379cd76ad25590c4059299b018eac6fbc50 (diff) | |
download | lwn-19fd2df5b1167eeb6ae8912cdfe9532e3b2c8bbe.tar.gz lwn-19fd2df5b1167eeb6ae8912cdfe9532e3b2c8bbe.zip |
Btrfs: fix btrfs_ordered_update_i_size to update disk_i_size properly
btrfs_ordered_update_i_size can be called by truncate and endio, but
only endio takes ordered_extent which contains the completed IO.
while truncating down a file, if there are some in-flight IOs,
btrfs_ordered_update_i_size in endio will set disk_i_size to
@orig_offset that is zero. If truncating-down fails somehow, we try to
recover in memory isize with this zero'd disk_i_size.
Fix it by only updating disk_i_size with @orig_offset when
btrfs_ordered_update_i_size is not called from endio while truncating
down and waiting for in-flight IOs completing their work before recover
in-memory size.
Besides fixing the above issue, add an assertion for last_size to double
check we truncate down to the desired size.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 4727b52c00e1..3944346265e8 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4695,6 +4695,13 @@ error: btrfs_free_path(path); + if (err == 0) { + /* only inline file may have last_size != new_size */ + if (new_size >= fs_info->sectorsize || + new_size > fs_info->max_inline) + ASSERT(last_size == new_size); + } + if (be_nice && bytes_deleted > SZ_32M) { unsigned long updates = trans->delayed_ref_updates; if (updates) { @@ -5080,6 +5087,13 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr) if (ret && inode->i_nlink) { int err; + /* To get a stable disk_i_size */ + err = btrfs_wait_ordered_range(inode, 0, (u64)-1); + if (err) { + btrfs_orphan_del(NULL, inode); + return err; + } + /* * failed to truncate, disk_i_size is only adjusted down * as we remove extents, so it should represent the true |