All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miklos Szeredi <mszeredi@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>,
	Alexei Starovoitov <ast@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 3/7] libfs: support RENAME_NOREPLACE in simple_rename()
Date: Tue, 23 Aug 2016 16:05:28 +0200	[thread overview]
Message-ID: <1471961132-1675-4-git-send-email-mszeredi@redhat.com> (raw)
In-Reply-To: <1471961132-1675-1-git-send-email-mszeredi@redhat.com>

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: Miklos Szeredi <mszeredi@redhat.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 fs/debugfs/inode.c   | 2 +-
 fs/hugetlbfs/inode.c | 2 +-
 fs/libfs.c           | 6 +++++-
 fs/ramfs/inode.c     | 2 +-
 include/linux/fs.h   | 3 ++-
 kernel/bpf/inode.c   | 2 +-
 6 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 72361baf9da7..5ac27c9de669 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -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);
 
 	error = simple_rename(d_inode(old_dir), old_dentry, d_inode(new_dir),
-		dentry);
+			      dentry, 0);
 	if (error) {
 		fsnotify_oldname_free(old_name);
 		goto exit;
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 4ea71eba40a5..50cd7475a942 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -988,7 +988,7 @@ static const struct inode_operations hugetlbfs_dir_inode_operations = {
 	.mkdir		= hugetlbfs_mkdir,
 	.rmdir		= simple_rmdir,
 	.mknod		= hugetlbfs_mknod,
-	.rename		= simple_rename,
+	.rename2	= simple_rename,
 	.setattr	= hugetlbfs_setattr,
 };
 
diff --git a/fs/libfs.c b/fs/libfs.c
index 74dc8b9e7f53..4758353b2d41 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -349,11 +349,15 @@ int simple_rmdir(struct inode *dir, struct dentry *dentry)
 EXPORT_SYMBOL(simple_rmdir);
 
 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);
 	int they_are_dirs = d_is_dir(old_dentry);
 
+	if (flags & ~RENAME_NOREPLACE)
+		return -EINVAL;
+
 	if (!simple_empty(new_dentry))
 		return -ENOTEMPTY;
 
diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index 1ab6e6c2e60e..c2aa068ff974 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -146,7 +146,7 @@ static const struct inode_operations ramfs_dir_inode_operations = {
 	.mkdir		= ramfs_mkdir,
 	.rmdir		= simple_rmdir,
 	.mknod		= ramfs_mknod,
-	.rename		= simple_rename,
+	.rename2	= simple_rename,
 };
 
 static const struct super_operations ramfs_ops = {
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 3523bf62f328..8aebcfc42f26 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2949,7 +2949,8 @@ extern int simple_open(struct inode *inode, struct file *file);
 extern int simple_link(struct dentry *, struct inode *, struct dentry *);
 extern int simple_unlink(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 simple_empty(struct dentry *);
 extern int simple_readpage(struct file *file, struct page *page);
diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c
index 5967b870a895..c92fd8936d33 100644
--- a/kernel/bpf/inode.c
+++ b/kernel/bpf/inode.c
@@ -189,7 +189,7 @@ static const struct inode_operations bpf_dir_iops = {
 	.mknod		= bpf_mkobj,
 	.mkdir		= bpf_mkdir,
 	.rmdir		= simple_rmdir,
-	.rename		= simple_rename,
+	.rename2	= simple_rename,
 	.link		= simple_link,
 	.unlink		= simple_unlink,
 };
-- 
2.5.5

  parent reply	other threads:[~2016-08-23 14:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-23 14:05 [PATCH 0/7] vfs: finish rename -> rename2 conversion Miklos Szeredi
2016-08-23 14:05 ` [PATCH 1/7] ncpfs: fix unused variable warning Miklos Szeredi
2016-08-23 14:05 ` [PATCH 2/7] fs: support RENAME_NOREPLACE for local filesystems Miklos Szeredi
2016-08-23 21:48   ` Richard Weinberger
2016-08-25 12:52   ` Bob Copeland
2016-09-08 13:55   ` Jan Kara
2016-08-23 14:05 ` Miklos Szeredi [this message]
2016-08-23 14:47   ` [PATCH 3/7] libfs: support RENAME_NOREPLACE in simple_rename() Greg Kroah-Hartman
2016-08-23 14:05 ` [PATCH 4/7] fs: make remaining filesystems use .rename2 Miklos Szeredi
2016-08-23 14:47   ` Greg Kroah-Hartman
2016-08-23 17:30     ` Mike Marshall
2016-08-23 16:24   ` Boaz Harrosh
2016-08-23 16:29     ` Boaz Harrosh
2016-08-23 14:05 ` [PATCH 5/7] vfs: remove unused i_op->rename Miklos Szeredi
2016-08-23 14:05 ` [PATCH 6/7] fs: rename "rename2" i_op to "rename" Miklos Szeredi
2016-08-23 14:05 ` [PATCH 7/7] vfs: add note about i_op->rename changes to porting Miklos Szeredi
2016-08-23 15:36 ` [PATCH 4/7] fs: make remaining filesystems use .rename2 David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471961132-1675-4-git-send-email-mszeredi@redhat.com \
    --to=mszeredi@redhat.com \
    --cc=ast@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.