[V2,1/2] Btrfs: fix the race between write back and nocow buffered write
diff mbox

Message ID 1389233170-27573-1-git-send-email-miaox@cn.fujitsu.com
State Accepted
Headers show

Commit Message

Miao Xie Jan. 9, 2014, 2:06 a.m. UTC
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
  Task1				Task2
    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>
Changelog v1 -> v2:
- rebase the patch to the btrfs-next tree
 fs/btrfs/file.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff mbox

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 453e43c..0218288 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1555,9 +1555,10 @@  again:
 					     lockstart, lockend, &cached_state,
-		btrfs_drop_pages(pages, num_pages);
-		if (ret)
+		if (ret) {
+			btrfs_drop_pages(pages, num_pages);
+		}
 		release_bytes = 0;
 		if (only_release_metadata && copied > 0) {
@@ -1571,6 +1572,8 @@  again:
 			only_release_metadata = false;
+		btrfs_drop_pages(pages, num_pages);