linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* cp --reflix between subvolume
@ 2020-08-25 18:03 Goffredo Baroncelli
  0 siblings, 0 replies; only message in thread
From: Goffredo Baroncelli @ 2020-08-25 18:03 UTC (permalink / raw)
  To: David Sterba; +Cc: linux-btrfs, Neal Gompa

Looking at this page [1] I discovered that in BTRFS it is possible to do a cp --reflink between different subvolume *only* if these are from the same mountpoint. If the subvolumes are mounted with "subvol=" this is not possible even if these are from the same filesystem.

$ cd /var/btrfs/
$ sudo btrfs sub crea a
Create subvolume './a'
$ sudo btrfs sub crea b
Create subvolume './b'
$ sudo dd if=/dev/zero of=a/zero bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0017188 s, 610 MB/s
$ sudo cp --reflink a/zero b/zero-1
$ ls b/
zero-1

$ # /dev/sde3 is the btrfs filesystem /var/btrfs
$ sudo mount -o subvol=b /dev/sde3 /mnt/other
$ ls /mnt/other
zero-1
$ sudo cp --reflink a/zero /mnt/other/zero-2
cp: failed to clone '/mnt/other/zero-2' from 'a/zero': Invalid cross-device link

@David,
it seems that the check that prevent 'cp --reflink' to work was inserted by you in the commit 362a20c5e27614739c46707d1c5f55c214d164ce:


$ git show 362a20c5e27614739c46707d1c5f55c214d164ce
commit 362a20c5e27614739c46707d1c5f55c214d164ce
Author: David Sterba <dsterba@suse.cz>
Date:   Mon Aug 1 18:11:57 2011 +0200

     btrfs: allow cross-subvolume file clone
     
     Lift the EXDEV condition and allow different root trees for files being
     cloned, then pass source inode's root when searching for extents.
     Cloning is not allowed to cross vfsmounts, ie. when two subvolumes from
     one filesystem are mounted separately.
     
     Signed-off-by: David Sterba <dsterba@suse.cz>

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 0e92e5763005..7011871c45b8 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2340,6 +2340,10 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
  		goto out_drop_write;
  	}
  
+	ret = -EXDEV;
+	if (src_file->f_path.mnt != file->f_path.mnt)
+		goto out_fput;
+
[...]

Now the code is changed from the one above. But there is the same check (only in a different position)

What is the rationale behind this check ? I checked that also nfs4 does the same check.
But I don't understand what is the reason (for sure there is one reason :-) ). My understanding is that
a cp --reflink should be allowed with the only condition that the filesystem are the same; and this check (== the superblock are the same)  are in place.

As also described in [1], the use case that I am looking an easy way to replace the root filesystem
with an its snapshot. So every sub-subvolume (under root) have to be moved between the different
root subvolumes and the easy way is to mount it via fstab. However doing so it prevents cp --reflink
to work.


[1] https://pagure.io/fedora-btrfs/project/issue/8

BR
G.Baroncelli

-- 
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-25 18:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-25 18:03 cp --reflix between subvolume Goffredo Baroncelli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).