• Wang Shilong's avatar
    Btrfs: fix snapshot vs nocow writting · e9894fd3
    Wang Shilong authored
    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: default avatarGui Hecheng <guihc.fnst@cn.fujitsu.com>
    Signed-off-by: default avatarWang Shilong <wangsl.fnst@cn.fujitsu.com>
    Signed-off-by: default avatarChris Mason <clm@fb.com>
    e9894fd3
inode.c 238 KB