]> git.baikalelectronics.ru Git - kernel.git/commitdiff
libfs: Support RENAME_EXCHANGE in simple_rename()
authorLorenz Bauer <lmb@cloudflare.com>
Thu, 28 Oct 2021 09:47:22 +0000 (10:47 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 3 Nov 2021 14:43:08 +0000 (15:43 +0100)
Allow atomic exchange via RENAME_EXCHANGE when using simple_rename.
This affects binderfs, ramfs, hubetlbfs and bpffs.

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Miklos Szeredi <mszeredi@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/bpf/20211028094724.59043-3-lmb@cloudflare.com
fs/libfs.c

index 1cf144dc9ed2881f583729e15b636e3b50a37397..ba7438ab93710f9df4ed44609ecc6947eeb0cf0b 100644 (file)
@@ -479,9 +479,12 @@ int simple_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
        struct inode *inode = d_inode(old_dentry);
        int they_are_dirs = d_is_dir(old_dentry);
 
-       if (flags & ~RENAME_NOREPLACE)
+       if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE))
                return -EINVAL;
 
+       if (flags & RENAME_EXCHANGE)
+               return simple_rename_exchange(old_dir, old_dentry, new_dir, new_dentry);
+
        if (!simple_empty(new_dentry))
                return -ENOTEMPTY;