tarka / xcp

An extended `cp`
GNU General Public License v3.0
747 stars 24 forks source link

[ Feature Request] Reflink support for btrfs? #20

Closed navneetankur closed 2 years ago

navneetankur commented 3 years ago

I couldn't find any mention of reflink on readme. Is it supported? if yes, is it automatic?

piotr-calus commented 3 years ago

The use of reflink appears to be automatic on the btrfs file system (and xfs).

~ cp --reflink=never file1.dat file2_cp_nocow.dat
~ cp --reflink=always file1.dat file2_cp_cow.dat
~ xcp file1.dat file2_xcp.dat
[00:00:00] [################## ... ##################] 0B/0B (0s)

~ btrfs filesystem du *
     Total   Exclusive  Set shared  Filename
  10.00MiB       0.00B    10.00MiB  file1.dat
  10.00MiB       0.00B    10.00MiB  file2_cp_cow.dat
  10.00MiB    10.00MiB       0.00B  file2_cp_nocow.dat
  10.00MiB       0.00B    10.00MiB  file2_xcp.dat

When COW is not enabled (eg. NODATACOW attribute set on file), a normal copy of the file is made:

~ rm file*
~ touch file1.dat
~ chattr +C file1.dat
~ dd if=/dev/urandom of=file1.dat bs=1M count=10
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0,153369 s, 68,4 MB/s
~ lsattr file1.dat 
---------------C------ file1.dat

~ cp file1.dat file2_cp.dat
~ xcp file1.dat file2_xcp.dat
[00:00:00] [################## ... ##################] 0B/0B (0s)

~ btrfs filesystem du *
     Total   Exclusive  Set shared  Filename
  10.00MiB    10.00MiB       0.00B  file1.dat
  10.00MiB    10.00MiB       0.00B  file2_cp.dat
  10.00MiB    10.00MiB       0.00B  file2_xcp.dat

Tested on Linux (5.14.6-3 x86_64), xcp 0.9.0