Commit f1de9683 authored by Miao Xie's avatar Miao Xie Committed by Chris Mason
Browse files

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
  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: default avatarTsutomu Itoh <>
Signed-off-by: default avatarMiao Xie <>
Signed-off-by: default avatarJosef Bacik <>
Signed-off-by: default avatarChris Mason <>
parent 7ef81ac8
......@@ -1591,9 +1591,10 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
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) {
......@@ -1607,6 +1608,8 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
only_release_metadata = false;
btrfs_drop_pages(pages, num_pages);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment