]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: qgroup: Prevent qgroup->reserved from going subzero
authorGoldwyn Rodrigues <rgoldwyn@suse.com>
Fri, 30 Sep 2016 15:40:52 +0000 (10:40 -0500)
committerDavid Sterba <dsterba@suse.com>
Mon, 24 Oct 2016 16:20:21 +0000 (18:20 +0200)
commitca56d2c3f7fe57b719cac869f7eeb7fad7ede58f
tree07905fb6c4265397f59fd380a1abe6120d685d24
parentb44a5ef0c7aea41a217abaa15b1ea94d4dafb2a2
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: a512ce4c13 ("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>
fs/btrfs/inode.c