Btrfs: fix snapshot vs nocow writting
authorWang Shilong <wangsl.fnst@cn.fujitsu.com>
Thu, 27 Mar 2014 03:12:25 +0000 (11:12 +0800)
committerChris Mason <clm@fb.com>
Mon, 7 Apr 2014 16:08:43 +0000 (09:08 -0700)
commite9894fd3e3b3c5ecaa096d32c2d2b79db8e64433
tree44c6c453a793fec1a8f83b4d0d14768d2f71260e
parent3ac0d7b96a268a98bd474cab8bce3a9f125aaccf
Btrfs: fix snapshot vs nocow writting

While running fsstress and snapshots concurrently, we will hit something
like followings:

Thread 1 Thread 2

|->fallocate
  |->write pages
    |->join transaction
       |->add ordered extent
    |->end transaction
|->flushing data
  |->creating pending snapshots
|->write data into src root's
   fallocated space

After above work flows finished, we will get a state that source and
snapshot root share same space, but source root have written data into
fallocated space, this will make fsck fail to verify checksums for
snapshot root's preallocating file extent data.Nocow writting also
has this same problem.

Fix this problem by syncing snapshots with nocow writting:

 1.for nocow writting,if there are pending snapshots, we will
 fall into COW way.

 2.if there are pending nocow writes, snapshots for this root
 will be blocked until nocow writting finish.

Reported-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/inode.c