]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commit
Btrfs: fix enospc in hole punching
authorRobbie Ko <robbieko@synology.com>
Fri, 28 Oct 2016 02:32:54 +0000 (10:32 +0800)
committerFilipe Manana <fdmanana@suse.com>
Wed, 30 Nov 2016 13:44:16 +0000 (13:44 +0000)
commit2cdaf447e8c411bb61d3d1c91fafbbdd59ef0db2
treea163b8a7a07f8044cf3b2278664515b0eddecc06
parent8d9eddad19467b008e0c881bc3133d7da94b7ec1
Btrfs: fix enospc in hole punching

The hole punching can result in adding new leafs (and as a consequence
new nodes) to the tree because when we find file extent items that span
beyond the hole range we may end up not deleting them (just adjusting
them, reducing their range by reducing their length or increasing their
offset field) and add new file extent items representing holes.

So after splitting a leaf (therefore creating a new one) to insert a new
file extent item representing a hole, a new node might be added to each
level of the tree in the worst case scenario (since there's a new key
and every parent node was full).

For example if a file has an extent item representing the range 0 to 64Mb
and we punch a hole in the range 1Mb to 20Mb, the existing extent item is
duplicated and one of the copies is adjusted to represent the range 0 to
1Mb, the other copy adjusted to represent the range 20Mb to 64Mb, and a
new file extent item representing a hole in the range 1Mb to 20Mb is
inserted.

Fix this by using btrfs_calc_trans_metadata_size() instead of
btrfs_calc_trunc_metadata_size(), so that enough metadata space is
reserved for the worst possible case.

Signed-off-by: Robbie Ko <robbieko@synology.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
[Modified changelog for clarity and correctness]
fs/btrfs/file.c