Btrfs: fix the race between write back and nocow buffered write
authorMiao Xie <miaox@cn.fujitsu.com>
Thu, 9 Jan 2014 02:06:10 +0000 (10:06 +0800)
committerChris Mason <clm@fb.com>
Tue, 28 Jan 2014 21:20:28 +0000 (13:20 -0800)
commitf1de968376340c97ac2d7acd25fa3107c398e0e5
tree7d09c1d875d894f496bc59079143a8f09b0ccd78
parent7ef81ac86c8a44ab9f4e6e04e1f4c9ea53615b8a
Btrfs: fix the race between write back and nocow buffered write

When we ran the 274th case of xfstests with nodatacow mount option,
We met the following warning message:
WARNING: CPU: 1 PID: 14185 at fs/btrfs/extent-tree.c:3734 btrfs_free_reserved_data_space+0xa6/0xd0

It is caused by the race between the write back and nocow buffered
write:
  Task1 Task2
  __btrfs_buffered_write()
    skip data reservation
    reserve the metadata space
    copy the data
    dirty the pages
    unlock the pages
write back the pages
release the data space
      becasue there is no
  noreserve flag
   set the noreserve flag

This patch fixes this problem by unlocking the pages after
the noreserve flag is set.

Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/file.c