diff options
author | Jeff Mahoney <jeffm@suse.com> | 2016-11-18 21:52:40 -0500 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-11-30 13:45:19 +0100 |
commit | 0c476a5d7f63bdae0b6188a191a6e9eb8f1024d7 (patch) | |
tree | 542a26d81c7e1b7741825cffff3b1acaa32bc69e | |
parent | f94480bd7be6bb1b0823d1036f3ee4ebe7450172 (diff) | |
download | linux-0c476a5d7f63bdae0b6188a191a6e9eb8f1024d7.tar.gz linux-0c476a5d7f63bdae0b6188a191a6e9eb8f1024d7.tar.bz2 linux-0c476a5d7f63bdae0b6188a191a6e9eb8f1024d7.zip |
btrfs: Ensure proper sector alignment for btrfs_free_reserved_data_space
This fixes the WARN_ON on BTRFS_I(inode)->reserved_extents in
btrfs_destroy_inode and the WARN_ON on nonzero delalloc bytes on umount
with qgroups enabled.
I was able to reproduce this by setting up a small (~500kb) quota limit
and writing a file one byte at a time until I hit the limit. The warnings
would all hit on umount.
The root cause is that we would reserve a block-sized range in both
the reservation and the quota in btrfs_check_data_free_space, but if we
encountered a problem (like e.g. EDQUOT), we would only release the single
byte in the qgroup reservation. That caused an iotree state split, which
increased the number of outstanding extents, in turn disallowing releasing
the metadata reservation.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | fs/btrfs/extent-tree.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 78fcc67e7b8c..c17b0d1b081f 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4322,6 +4322,13 @@ void btrfs_free_reserved_data_space_noquota(struct inode *inode, u64 start, */ void btrfs_free_reserved_data_space(struct inode *inode, u64 start, u64 len) { + struct btrfs_root *root = BTRFS_I(inode)->root; + + /* Make sure the range is aligned to sectorsize */ + len = round_up(start + len, root->sectorsize) - + round_down(start, root->sectorsize); + start = round_down(start, root->sectorsize); + btrfs_free_reserved_data_space_noquota(inode, start, len); btrfs_qgroup_free_data(inode, start, len); } |