Commit e0e0be8a authored by Miklos Szeredi's avatar Miklos Szeredi

libfs: support RENAME_NOREPLACE in simple_rename()

This is trivial to do:

 - add flags argument to simple_rename()
 - check if flags doesn't have any other than RENAME_NOREPLACE
 - assign simple_rename() to .rename2 instead of .rename

Filesystems converted:

hugetlbfs, ramfs, bpf.

Debugfs uses simple_rename() to implement debugfs_rename(), which is for
debugfs instances to rename files internally, not for userspace filesystem
access.  For this case pass zero flags to simple_rename().
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Alexei Starovoitov <ast@kernel.org>
parent f03b8ad8
...@@ -748,7 +748,7 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry, ...@@ -748,7 +748,7 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
old_name = fsnotify_oldname_init(old_dentry->d_name.name); old_name = fsnotify_oldname_init(old_dentry->d_name.name);
error = simple_rename(d_inode(old_dir), old_dentry, d_inode(new_dir), error = simple_rename(d_inode(old_dir), old_dentry, d_inode(new_dir),
dentry); dentry, 0);
if (error) { if (error) {
fsnotify_oldname_free(old_name); fsnotify_oldname_free(old_name);
goto exit; goto exit;
......
...@@ -988,7 +988,7 @@ static const struct inode_operations hugetlbfs_dir_inode_operations = { ...@@ -988,7 +988,7 @@ static const struct inode_operations hugetlbfs_dir_inode_operations = {
.mkdir = hugetlbfs_mkdir, .mkdir = hugetlbfs_mkdir,
.rmdir = simple_rmdir, .rmdir = simple_rmdir,
.mknod = hugetlbfs_mknod, .mknod = hugetlbfs_mknod,
.rename = simple_rename, .rename2 = simple_rename,
.setattr = hugetlbfs_setattr, .setattr = hugetlbfs_setattr,
}; };
......
...@@ -349,11 +349,15 @@ int simple_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -349,11 +349,15 @@ int simple_rmdir(struct inode *dir, struct dentry *dentry)
EXPORT_SYMBOL(simple_rmdir); EXPORT_SYMBOL(simple_rmdir);
int simple_rename(struct inode *old_dir, struct dentry *old_dentry, int simple_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry) struct inode *new_dir, struct dentry *new_dentry,
unsigned int flags)
{ {
struct inode *inode = d_inode(old_dentry); struct inode *inode = d_inode(old_dentry);
int they_are_dirs = d_is_dir(old_dentry); int they_are_dirs = d_is_dir(old_dentry);
if (flags & ~RENAME_NOREPLACE)
return -EINVAL;
if (!simple_empty(new_dentry)) if (!simple_empty(new_dentry))
return -ENOTEMPTY; return -ENOTEMPTY;
......
...@@ -146,7 +146,7 @@ static const struct inode_operations ramfs_dir_inode_operations = { ...@@ -146,7 +146,7 @@ static const struct inode_operations ramfs_dir_inode_operations = {
.mkdir = ramfs_mkdir, .mkdir = ramfs_mkdir,
.rmdir = simple_rmdir, .rmdir = simple_rmdir,
.mknod = ramfs_mknod, .mknod = ramfs_mknod,
.rename = simple_rename, .rename2 = simple_rename,
}; };
static const struct super_operations ramfs_ops = { static const struct super_operations ramfs_ops = {
......
...@@ -2950,7 +2950,8 @@ extern int simple_open(struct inode *inode, struct file *file); ...@@ -2950,7 +2950,8 @@ extern int simple_open(struct inode *inode, struct file *file);
extern int simple_link(struct dentry *, struct inode *, struct dentry *); extern int simple_link(struct dentry *, struct inode *, struct dentry *);
extern int simple_unlink(struct inode *, struct dentry *); extern int simple_unlink(struct inode *, struct dentry *);
extern int simple_rmdir(struct inode *, struct dentry *); extern int simple_rmdir(struct inode *, struct dentry *);
extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); extern int simple_rename(struct inode *, struct dentry *,
struct inode *, struct dentry *, unsigned int);
extern int noop_fsync(struct file *, loff_t, loff_t, int); extern int noop_fsync(struct file *, loff_t, loff_t, int);
extern int simple_empty(struct dentry *); extern int simple_empty(struct dentry *);
extern int simple_readpage(struct file *file, struct page *page); extern int simple_readpage(struct file *file, struct page *page);
......
...@@ -189,7 +189,7 @@ static const struct inode_operations bpf_dir_iops = { ...@@ -189,7 +189,7 @@ static const struct inode_operations bpf_dir_iops = {
.mknod = bpf_mkobj, .mknod = bpf_mkobj,
.mkdir = bpf_mkdir, .mkdir = bpf_mkdir,
.rmdir = simple_rmdir, .rmdir = simple_rmdir,
.rename = simple_rename, .rename2 = simple_rename,
.link = simple_link, .link = simple_link,
.unlink = simple_unlink, .unlink = simple_unlink,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment