diff options
author | Lorenz Bauer <[email protected]> | 2021-10-28 10:47:22 +0100 |
---|---|---|
committer | Daniel Borkmann <[email protected]> | 2021-11-03 15:43:08 +0100 |
commit | 3871cb8cf741dcd8ebaec4f960be9479da2f176b (patch) | |
tree | a26293e5a380349df45fb4fb41f404112b0bade6 | |
parent | 6429e46304ac7820eebbea2bf5d73b90c18e0e06 (diff) |
libfs: Support RENAME_EXCHANGE in simple_rename()
Allow atomic exchange via RENAME_EXCHANGE when using simple_rename.
This affects binderfs, ramfs, hubetlbfs and bpffs.
Signed-off-by: Lorenz Bauer <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Acked-by: Christian Brauner <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Miklos Szeredi <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
-rw-r--r-- | fs/libfs.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/fs/libfs.c b/fs/libfs.c index 1cf144dc9ed2..ba7438ab9371 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -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; |