Skip to contentSkip to conversation

fs: allow do_renameat2() over bind mounts of the same filesystem.

PATCH In review Florian Margaine 3 participants 5 messages Aug 28, 2020 – Aug 29, 2020 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: allow do_renameat2() over bind mounts of the same filesystem.

There's currently this seemingly unnecessary limitation that rename() cannot work over bind mounts of the same filesystem, because the current check is against the vfsmount, not over the superblock. Given that the path in do_renameat2() is using dentries, the rename is properly supported across different mount points, because it is supported as it is the same superblock.

---
 fs/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/namei.c +1 -1
index e99e2a9da0f7..863e5be88278 100644
@@ -4386,7 +4386,7 @@ static int do_renameat2(int olddfd, const char __user *oldname, int newdfd,
 	}
 
 	error = -EXDEV;
-	if (old_path.mnt != new_path.mnt)
+	if (old_path.mnt->mnt_sb != new_path.mnt->mnt_sb)
 		goto exit2;
 
 	error = -EBUSY;
Signature · 1 line
2.26.2
maintainer
#1 lore raw
Quoted 2 lines · Florian Margaine

There's currently this seemingly unnecessary limitation that rename() cannot work over bind mounts of the same filesystem,

... is absolutely deliberate - that's how you set a boundary in the tree, preventing both links and renames across it.

Incidentally, doing that would have fun effects for anyone with current directory inside the subtree you'd moved - try and see.

#2 lore raw
Quoted 6 lines · Al Viro
Quoted 2 lines · Florian Margaine

There's currently this seemingly unnecessary limitation that rename() cannot work over bind mounts of the same filesystem,

... is absolutely deliberate - that's how you set a boundary in the tree, preventing both links and renames across it.

Sorry, I'm not not sure I understand what you're saying.

As I understand it, the tree is the superblock there, not the mount. As in, the dentries are relative to the superblock, and the mountpoint is no more than a pointer to a superblock's dentry.

In addition, I noticed this snippet in fs/read_write.c:

    /*
     * FICLONE/FICLONERANGE ioctls enforce that src and dest files are on
     * the same mount. Practically, they only need to be on the same file
     * system.
     */
    if (file_inode(file_in)->i_sb != file_inode(file_out)->i_sb)
        return -EXDEV;

Which seems to confirm my understanding.

What am I getting wrong there?

Quoted 3 lines

Incidentally, doing that would have fun effects for anyone with current directory inside the subtree you'd moved - try and see.

#3 lore raw
Quoted 10 lines · Florian Margaine
Quoted 6 lines · Al Viro
Quoted 2 lines · Florian Margaine

There's currently this seemingly unnecessary limitation that rename() cannot work over bind mounts of the same filesystem,

... is absolutely deliberate - that's how you set a boundary in the tree, preventing both links and renames across it.

Sorry, I'm not not sure I understand what you're saying.

Al's saying this is the way an administrator can intentionally prevent renames.

Quoted 7 lines
    /*
     * FICLONE/FICLONERANGE ioctls enforce that src and dest files are on
     * the same mount. Practically, they only need to be on the same file
     * system.
     */
    if (file_inode(file_in)->i_sb != file_inode(file_out)->i_sb)
        return -EXDEV;

clone doesn't change the contents of a file, merely how they're laid out on storage. There's no particular reason for an administrator to prohibit clone across mount points.

#4 lore raw
Quoted 7 lines · Matthew Wilcox
Quoted 6 lines · Florian Margaine
Quoted 4 lines · Al Viro
Quoted 2 lines · Florian Margaine

There's currently this seemingly unnecessary limitation that rename() cannot work over bind mounts of the same filesystem,

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

... is absolutely deliberate - that's how you set a boundary in the tree, preventing both links and renames across it.

Sorry, I'm not not sure I understand what you're saying.

Al's saying this is the way an administrator can intentionally prevent renames.

Ah, ok. Thanks!

Quoted 12 lines
Quoted 8 lines
    /*
     * FICLONE/FICLONERANGE ioctls enforce that src and dest files are on
     * the same mount. Practically, they only need to be on the same file
     * system.
     */
    if (file_inode(file_in)->i_sb != file_inode(file_out)->i_sb)
        return -EXDEV;

clone doesn't change the contents of a file, merely how they're laid out on storage. There's no particular reason for an administrator to prohibit clone across mount points.