Skip to contentSkip to conversation

Allow cross subvolume reflinks (2nd attempt)

PATCH In review Alexander Block 5 participants 9 messages Jun 20, 2012 – Jun 27, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow cross subvolume reflinks (2nd attempt)

Hello,

This is the second attempt to bring in cross subvolume reflinks into btrfs. The first attempt was NAKed due to missing vfs mount checks and a clear description of what btrfs subvolumes are and probably also why cross subvolume reflinks are ok in the case of btrfs. This version of the patch comes from David and is in SUSE kernels since a long time, so it is tested and working. The patch also does proper vfs mount checks, so cross mount point reflinks are not possible with this patch. It only allows cross reflinks between two subvolumes which are in the same mount point.

As requested in the older discussion, I'll try to describe what subvolumes in btrfs are. From the users point of view, a subvolume is just a directory in the mounted fs with its own inode space. This means, that two inodes with the same number from different subvolumes are different files. Parallel to the sub directory form, a subvolume may be mounted in its own vfs mount point (I'm however not sure if this is already possible or just planned). Internally, a btrfs subvolume is a separate btree, containing all the metadata needed to store the fs of the subvolume. Additionally to the subvolumes, btrfs has snapshots, which are basically the same as subvolumes, with the difference that they share metadata and data with the snapshot origin/parent. Everything that applies to subvolumes also applies to snapshots.

The clone ioctl requires the destination file to be already existing and opened for writing. This means that we do not touch any vfs semantics regarding creation/opening of files. The ioctl only copies the extents information from the source to the destination, doing proper access checks before. In my opinion, we can compare the clone ioctl to the sendfile syscall, with the difference that we don't copy data but the information where the data lies.

Link to the old discussion:
http://thread.gmane.org/gmane.comp.file-systems.btrfs/9864
Only PATCH 2/2 is of interrest now. The discussion also contains some arguments why cross subvolume reflinks are a good thing, but I think this should not be the matter of the new discussion.

Alex.

David Sterba (1):
btrfs: allow cross-subvolume file clone

 fs/btrfs/ioctl.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.10
#1 lore raw

PATCH 1/1 btrfs: allow cross-subvolume file clone

From: David Sterba <[email protected]>

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.

---
 fs/btrfs/ioctl.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
fs/btrfs/ioctl.c +8 -3
index 00fd8b5..9e89255 100644
@@ -2352,6 +2352,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;
+
 	src = src_file->f_dentry->d_inode;
 
 	ret = -EINVAL;
@@ -2372,7 +2376,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
 		goto out_fput;
 
 	ret = -EXDEV;
-	if (src->i_sb != inode->i_sb || BTRFS_I(src)->root != root)
+	if (src->i_sb != inode->i_sb)
 		goto out_fput;
 
 	ret = -ENOMEM;
@@ -2446,13 +2450,14 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
 		 * note the key will change type as we walk through the
 		 * tree.
 		 */
-		ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
+		ret = btrfs_search_slot(NULL, BTRFS_I(src)->root, &key, path,
+				0, 0);
 		if (ret < 0)
 			goto out;
 
 		nritems = btrfs_header_nritems(path->nodes[0]);
 		if (path->slots[0] >= nritems) {
-			ret = btrfs_next_leaf(root, path);
+			ret = btrfs_next_leaf(BTRFS_I(src)->root, path);
 			if (ret < 0)
 				goto out;
 			if (ret > 0)
Signature · 1 line
1.7.10
#2 lore raw
In reply to Alexander Block

Hi Alexander,

Quoted 3 lines · Alexander Block

The patch also does proper vfs mount checks, so cross mount point reflinks are not possible with this patch. It only allows cross reflinks between two subvolumes which are in the same mount point.

Thanks for working on that. What happens if two subvolumes of the same filesystem are mounted on two different places ?

I usually do:
mount -o subvol=__active /dev/sdX /
mount -o subvol=. /dev/sdX /var/btrfs

So two different subvolumes of the same filesystem (the one on /dev/sdX) are mounted on two different places.

Is it possible to do
cp --reflink /tmp/foo /var/btrfs/tmp/foo2

Thanks
G.Baroncelli

#3 lore raw
Quoted 14 lines · Goffredo Baroncelli

Hi Alexander,

Quoted 3 lines · Alexander Block

The patch also does proper vfs mount checks, so cross mount point reflinks are not possible with this patch. It only allows cross reflinks between two subvolumes which are in the same mount point.

Thanks for working on that. What happens if two subvolumes of the same filesystem are mounted on two different places ?

I usually do:
 mount -o subvol=__active /dev/sdX /
 mount -o subvol=.        /dev/sdX /var/btrfs

Quoted 5 lines

So two different subvolumes of the same filesystem (the one on /dev/sdX) are mounted on two different places.

Is it possible to do
 cp --reflink /tmp/foo /var/btrfs/tmp/foo2

This will fail with -EXDEV. The patch explicitly forbids reflinks crossing vfs mount boundaries.

Quoted 4 lines

Thanks
G.Baroncelli

#4 lore raw
Quoted 15 lines · Alexander Block
Quoted 14 lines · Goffredo Baroncelli

Hi Alexander,

Quoted 3 lines · Alexander Block

The patch also does proper vfs mount checks, so cross mount point reflinks are not possible with this patch. It only allows cross reflinks between two subvolumes which are in the same mount point.

Thanks for working on that. What happens if two subvolumes of the same filesystem are mounted on two different places ?

I usually do:
mount -o subvol=__active /dev/sdX /
mount -o subvol=. /dev/sdX /var/btrfs

Quoted 7 lines
Quoted 5 lines

So two different subvolumes of the same filesystem (the one on /dev/sdX) are mounted on two different places.

Is it possible to do
cp --reflink /tmp/foo /var/btrfs/tmp/foo2

This will fail with -EXDEV. The patch explicitly forbids reflinks crossing vfs mount boundaries.

Which means that if I want to do a reflink copy between two separately mounted subvolumes, I will have to go and do a third mount with a common subvolume above those two, then do the reflink operation within this extra mount? This seems slightly impractical.

Is it any extra code to enable doing cross-mount reflinks? Why was the decision made not to allow them?

Is there some particular opposition to supporting cross-mount operations on multiple mounts of the same filesystem in general? (I'd love to have rename() work across bind mounts, for example...)

Signature · 1 line
Calvin Walton <[email protected]>
#5 lore raw
Quoted 29 lines · Calvin Walton
Quoted 15 lines · Alexander Block
Quoted 14 lines · Goffredo Baroncelli

Hi Alexander,

Quoted 3 lines · Alexander Block

The patch also does proper vfs mount checks, so cross mount point reflinks are not possible with this patch. It only allows cross reflinks between two subvolumes which are in the same mount point.

Thanks for working on that. What happens if two subvolumes of the same filesystem are mounted on two different places ?

I usually do:
mount -o subvol=__active /dev/sdX /
mount -o subvol=. /dev/sdX /var/btrfs

Quoted 7 lines
Quoted 5 lines

So two different subvolumes of the same filesystem (the one on /dev/sdX) are mounted on two different places.

Is it possible to do
cp --reflink /tmp/foo /var/btrfs/tmp/foo2

This will fail with -EXDEV. The patch explicitly forbids reflinks crossing vfs mount boundaries.

Which means that if I want to do a reflink copy between two separately mounted subvolumes, I will have to go and do a third mount with a common subvolume above those two, then do the reflink operation within this extra mount? This seems slightly impractical.

Quoted 6 lines

Is it any extra code to enable doing cross-mount reflinks? Why was the decision made not to allow them?

Is there some particular opposition to supporting cross-mount operations on multiple mounts of the same filesystem in general? (I'd love to have rename() work across bind mounts, for example...)

Yes please, could someone explain the reason behind this decision ? May be there are valid reasons, I am asking only to know which ones ?

#6 lore raw
Quoted 4 lines · Goffredo Baroncelli

Yes please, could someone explain the reason behind this decision ? May be there are valid reasons, I am asking only to know which ones ?

The reason is that at the moment no user visible operations span mount boundaries
and there were discussion on whether this should be allowed for the clone ioctl or
not. For the moment, I would already be happy to have cross subvolume reflinks which do not span mount points, this would already be much more as we have at the moment.

#7 lore raw
Quoted 10 lines · Alexander Block
Quoted 4 lines · Goffredo Baroncelli

Yes please, could someone explain the reason behind this decision ? May be there are valid reasons, I am asking only to know which ones ?

The reason is that at the moment no user visible operations span mount boundaries
and there were discussion on whether this should be allowed for the clone ioctl or
not.

Yes, I understood the same. But nobody was able to explain why .

For the moment, I would already be happy to have cross subvolume reflinks

Quoted 2 lines

which do not span mount points, this would already be much more as we have at the moment.

This is reasonable.

Quoted 2 lines

.

#8 lore raw
In reply to Alexander Block
Quoted 10 lines · Alexander Block

Hello,

This is the second attempt to bring in cross subvolume reflinks into btrfs. The first attempt was NAKed due to missing vfs mount checks and a clear description of what btrfs subvolumes are and probably also why cross subvolume reflinks are ok in the case of btrfs. This version of the patch comes from David and is in SUSE kernels since a long time, so it is tested and working. The patch also does proper vfs mount checks, so cross mount point reflinks are not possible with this patch. It only allows cross reflinks between two subvolumes which are in the same mount point.

Thank you for bringing this back. This would have saved me a lot of trouble

I'm not familiar with the code, but here's a big thumbs up from me.

Anyone doing reviews, please consider this :)

Thanks,
Marc

Signature · 4 lines
"A mouse is a device used to point at the xterm you want to type in" - A.S.R.
Microsoft is to operating systems ....
                                      .... what McDonalds is to gourmet cooking
Home page: http://marc.merlins.org/