Koen De Wit
2012-Dec-11 22:16 UTC
Bug: trying to create reflink on different device results in empty file
When trying to create a clone (reflink) of a file on a different device, you''ll get this error: Invalid cross-device link However, an empty file is created on the target location. An invalid clone operation should not result in the creation of a file. Example: # mount (...) /dev/sdb1 on /mnt/diskb type btrfs (rw) /dev/sdf1 on /mnt/diskf type btrfs (rw) # ls -l diskb total 4 -rw-r--r-- 1 root root 11 Dec 11 22:45 testfile.txt # ls -l diskf total 0 # cp --reflink diskb/testfile.txt diskf/testcopy.txt cp: failed to clone `diskf/testcopy.txt'' from `diskb/testfile.txt'': Invalid cross-device link # ls -l diskf total 0 -rw-r--r-- 1 root root 0 Dec 11 22:56 testcopy.txt -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2012-Dec-19 16:04 UTC
Re: Bug: trying to create reflink on different device results in empty file
On Tue, Dec 11, 2012 at 11:16:03PM +0100, Koen De Wit wrote:> When trying to create a clone (reflink) of a file on a different device, > you''ll get this error: > Invalid cross-device link > > However, an empty file is created on the target location. An invalid clone > operation should not result in the creation of a file.The clone operation inside btrfs needs 2 files already open (ie. it works with file descriptors, not with filenames), the empty file exists prior to the ioctl call. So the file should be removed by ''cp'' (or whoever calls the clone ioctl) because they know if it makes sense to delete the file or not. david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html