diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 2ae5a9b2f951..f6ca6a76730e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1943,6 +1943,11 @@ static int can_nocow_file_extent(struct btrfs_path *path, int ret = 0; bool nowait = path->nowait; + /* If there are pending snapshots for this root, we must do COW. */ + if (args->writeback_path && !is_freespace_inode && + atomic_read(&root->snapshot_force_cow)) + goto out; + fi = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_file_extent_item); extent_type = btrfs_file_extent_type(leaf, fi); @@ -2004,11 +2009,6 @@ static int can_nocow_file_extent(struct btrfs_path *path, path = NULL; } - /* If there are pending snapshots for this root, we must COW. */ - if (args->writeback_path && !is_freespace_inode && - atomic_read(&root->snapshot_force_cow)) - goto out; - args->file_extent.num_bytes = min(args->end + 1, extent_end) - args->start; args->file_extent.offset += args->start - key->offset; io_start = args->file_extent.disk_bytenr + args->file_extent.offset;