Btrfs: fix preallocate vs double nocow write
authorMiao Xie <miaox@cn.fujitsu.com>
Thu, 27 Feb 2014 05:58:05 +0000 (13:58 +0800)
committerJosef Bacik <jbacik@fb.com>
Mon, 10 Mar 2014 19:17:00 +0000 (15:17 -0400)
commit7b2b70851f862b68714f357d2926adbb6c574fdd
treeb1f0715cb4140c4ddd63bf3c6e70f1900c8b9acf
parentc933956ddf80bc455d33cbcf39d35d935daf45a9
Btrfs: fix preallocate vs double nocow write

We can not release the reserved metadata space for the first write if we
find the write position is pre-allocated. Because the kernel might write
the data on the disk before we do the second write but after the can-nocow
check, if we release the space for the first write, we might fail to update
the metadata because of no space.

Fix this problem by end nocow write if there is dirty data in the range whose
space is pre-allocated.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
fs/btrfs/file.c
fs/btrfs/inode.c