diff options
author | Goldwyn Rodrigues <rgoldwyn@suse.com> | 2016-09-30 11:40:52 -0400 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-10-24 12:20:21 -0400 |
commit | 0b34c261e235a5c74dcf78bd305845bd15fe2b42 (patch) | |
tree | 07905fb6c4265397f59fd380a1abe6120d685d24 | |
parent | 4547f4d8ffd63ba4ac129f9136027bd14b729101 (diff) |
btrfs: qgroup: Prevent qgroup->reserved from going subzero
While free'ing qgroup->reserved resources, we much check if
the page has not been invalidated by a truncate operation
by checking if the page is still dirty before reducing the
qgroup resources. Resources in such a case are free'd when
the entire extent is released by delayed_ref.
This fixes a double accounting while releasing resources
in case of truncating a file, reproduced by the following testcase.
SCRATCH_DEV=/dev/vdb
SCRATCH_MNT=/mnt
mkfs.btrfs -f $SCRATCH_DEV
mount -t btrfs $SCRATCH_DEV $SCRATCH_MNT
cd $SCRATCH_MNT
btrfs quota enable $SCRATCH_MNT
btrfs subvolume create a
btrfs qgroup limit 500m a $SCRATCH_MNT
sync
for c in {1..15}; do
dd if=/dev/zero bs=1M count=40 of=$SCRATCH_MNT/a/file;
done
sleep 10
sync
sleep 5
touch $SCRATCH_MNT/a/newfile
echo "Removing file"
rm $SCRATCH_MNT/a/file
Fixes: b9d0b38928 ("btrfs: Add handler for invalidate page")
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | fs/btrfs/inode.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 50ba4ca167e7..6677674d0505 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -8930,9 +8930,14 @@ again: | |||
8930 | * So even we call qgroup_free_data(), it won't decrease reserved | 8930 | * So even we call qgroup_free_data(), it won't decrease reserved |
8931 | * space. | 8931 | * space. |
8932 | * 2) Not written to disk | 8932 | * 2) Not written to disk |
8933 | * This means the reserved space should be freed here. | 8933 | * This means the reserved space should be freed here. However, |
8934 | * if a truncate invalidates the page (by clearing PageDirty) | ||
8935 | * and the page is accounted for while allocating extent | ||
8936 | * in btrfs_check_data_free_space() we let delayed_ref to | ||
8937 | * free the entire extent. | ||
8934 | */ | 8938 | */ |
8935 | btrfs_qgroup_free_data(inode, page_start, PAGE_SIZE); | 8939 | if (PageDirty(page)) |
8940 | btrfs_qgroup_free_data(inode, page_start, PAGE_SIZE); | ||
8936 | if (!inode_evicting) { | 8941 | if (!inode_evicting) { |
8937 | clear_extent_bit(tree, page_start, page_end, | 8942 | clear_extent_bit(tree, page_start, page_end, |
8938 | EXTENT_LOCKED | EXTENT_DIRTY | | 8943 | EXTENT_LOCKED | EXTENT_DIRTY | |