Btrfs: __btrfs_buffered_write: Pass valid file offset when releasing delalloc space
authorChandan Rajendra <chandan@linux.vnet.ibm.com>
Sun, 3 Apr 2016 21:23:06 +0000 (02:53 +0530)
committerDavid Sterba <dsterba@suse.com>
Thu, 28 Apr 2016 08:41:47 +0000 (10:41 +0200)
The delalloc reserved space is calculated in terms of number of bytes
used by an integral number of blocks. This is done by rounding down the
value of 'pos' to the nearest multiple of sectorsize.

The file offset value held by 'pos' variable may not be aligned to
sectorsize and hence when passing it as an argument to
btrfs_delalloc_release_space(), we may end up releasing larger delalloc
space than we originally had reserved.

Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/file.c

index 751daacd268d8b5568bb7ff5ceda94eb90e2309e..af059c44684dcef797d9b1e5f6e319ab6bba4f5e 100644 (file)
@@ -1696,7 +1696,9 @@ again:
                        btrfs_end_write_no_snapshoting(root);
                        btrfs_delalloc_release_metadata(inode, release_bytes);
                } else {
-                       btrfs_delalloc_release_space(inode, pos, release_bytes);
+                       btrfs_delalloc_release_space(inode,
+                                               round_down(pos, root->sectorsize),
+                                               release_bytes);
                }
        }