linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miklos Szeredi <miklos@szeredi.hu>
To: akpm@linux-foundation.org
Cc: hch@infradead.org, viro@ZenIV.linux.org.uk,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [patch 21/24] vfs: add path_rename()
Date: Tue, 06 May 2008 11:13:48 +0200	[thread overview]
Message-ID: <20080506091440.391186713@szeredi.hu> (raw)
In-Reply-To: 20080506091327.259950960@szeredi.hu

[-- Attachment #1: path_rename.patch --]
[-- Type: text/plain, Size: 6710 bytes --]

From: Miklos Szeredi <mszeredi@suse.cz>

Introduce path_rename().  Make vfs_rename() static.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
---
 fs/ecryptfs/inode.c |   22 ++++++++++++----------
 fs/namei.c          |   33 ++++++++++++++++++++++++---------
 fs/nfsd/vfs.c       |   19 +++++--------------
 include/linux/fs.h  |    3 ++-
 4 files changed, 43 insertions(+), 34 deletions(-)

Index: linux-2.6/fs/ecryptfs/inode.c
===================================================================
--- linux-2.6.orig/fs/ecryptfs/inode.c	2008-05-06 11:04:40.000000000 +0200
+++ linux-2.6/fs/ecryptfs/inode.c	2008-05-06 11:04:41.000000000 +0200
@@ -555,25 +555,27 @@ ecryptfs_rename(struct inode *old_dir, s
 	int rc;
 	struct dentry *lower_old_dentry;
 	struct dentry *lower_new_dentry;
-	struct dentry *lower_old_dir_dentry;
-	struct dentry *lower_new_dir_dentry;
+	struct path lower_old_dir;
+	struct path lower_new_dir;
 
 	lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
 	lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
 	dget(lower_old_dentry);
 	dget(lower_new_dentry);
-	lower_old_dir_dentry = dget_parent(lower_old_dentry);
-	lower_new_dir_dentry = dget_parent(lower_new_dentry);
-	lock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
-	rc = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry,
-			lower_new_dir_dentry->d_inode, lower_new_dentry);
+	lower_old_dir.mnt = ecryptfs_dentry_to_lower_mnt(old_dentry);
+	lower_old_dir.dentry = dget_parent(lower_old_dentry);
+	lower_new_dir.mnt = ecryptfs_dentry_to_lower_mnt(new_dentry);
+	lower_new_dir.dentry = dget_parent(lower_new_dentry);
+	lock_rename(lower_old_dir.dentry, lower_new_dir.dentry);
+	rc = path_rename(&lower_old_dir, lower_old_dentry,
+			 &lower_new_dir, lower_new_dentry);
 	if (rc)
 		goto out_lock;
-	fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode, NULL);
+	fsstack_copy_attr_all(new_dir, lower_new_dir.dentry->d_inode, NULL);
 	if (new_dir != old_dir)
-		fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode, NULL);
+		fsstack_copy_attr_all(old_dir, lower_old_dir.dentry->d_inode, NULL);
 out_lock:
-	unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
+	unlock_rename(lower_old_dir.dentry, lower_new_dir.dentry);
 	dput(lower_new_dentry->d_parent);
 	dput(lower_old_dentry->d_parent);
 	dput(lower_new_dentry);
Index: linux-2.6/fs/namei.c
===================================================================
--- linux-2.6.orig/fs/namei.c	2008-05-06 11:04:40.000000000 +0200
+++ linux-2.6/fs/namei.c	2008-05-06 11:04:41.000000000 +0200
@@ -2730,8 +2730,8 @@ static int vfs_rename_other(struct inode
 	return error;
 }
 
-int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
-	       struct inode *new_dir, struct dentry *new_dentry)
+static int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
+		      struct inode *new_dir, struct dentry *new_dentry)
 {
 	int error;
 	int is_dir = S_ISDIR(old_dentry->d_inode->i_mode);
@@ -2773,6 +2773,27 @@ int vfs_rename(struct inode *old_dir, st
 	return error;
 }
 
+int path_rename(struct path *old_dir_path, struct dentry *old_dentry,
+		struct path *new_dir_path, struct dentry *new_dentry)
+{
+	int error;
+	struct vfsmount *mnt = old_dir_path->mnt;
+
+	BUG_ON(mnt != new_dir_path->mnt);
+
+	error = mnt_want_write(mnt);
+	if (!error) {
+		struct inode *old_dir = old_dir_path->dentry->d_inode;
+		struct inode *new_dir = new_dir_path->dentry->d_inode;
+
+		error = vfs_rename(old_dir, old_dentry, new_dir, new_dentry);
+		mnt_drop_write(mnt);
+	}
+
+	return error;
+}
+EXPORT_SYMBOL(path_rename);
+
 static int do_rename(int olddfd, const char *oldname,
 			int newdfd, const char *newname)
 {
@@ -2834,12 +2855,7 @@ static int do_rename(int olddfd, const c
 	if (new_dentry == trap)
 		goto exit5;
 
-	error = mnt_want_write(oldnd.path.mnt);
-	if (error)
-		goto exit5;
-	error = vfs_rename(old_dir->d_inode, old_dentry,
-				   new_dir->d_inode, new_dentry);
-	mnt_drop_write(oldnd.path.mnt);
+	error = path_rename(&oldnd.path, old_dentry, &newnd.path, new_dentry);
 exit5:
 	dput(new_dentry);
 exit4:
@@ -3030,6 +3046,5 @@ EXPORT_SYMBOL(unlock_rename);
 EXPORT_SYMBOL(vfs_follow_link);
 EXPORT_SYMBOL(generic_permission);
 EXPORT_SYMBOL(vfs_readlink);
-EXPORT_SYMBOL(vfs_rename);
 EXPORT_SYMBOL(dentry_unhash);
 EXPORT_SYMBOL(generic_readlink);
Index: linux-2.6/fs/nfsd/vfs.c
===================================================================
--- linux-2.6.orig/fs/nfsd/vfs.c	2008-05-06 11:04:40.000000000 +0200
+++ linux-2.6/fs/nfsd/vfs.c	2008-05-06 11:04:41.000000000 +0200
@@ -1650,8 +1650,9 @@ __be32
 nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
 			    struct svc_fh *tfhp, char *tname, int tlen)
 {
+	struct path 	old_dir_path;
+	struct path	new_dir_path;
 	struct dentry	*fdentry, *tdentry, *odentry, *ndentry, *trap;
-	struct inode	*fdir, *tdir;
 	__be32		err;
 	int		host_err;
 
@@ -1663,10 +1664,7 @@ nfsd_rename(struct svc_rqst *rqstp, stru
 		goto out;
 
 	fdentry = ffhp->fh_dentry;
-	fdir = fdentry->d_inode;
-
 	tdentry = tfhp->fh_dentry;
-	tdir = tdentry->d_inode;
 
 	err = (rqstp->rq_vers == 2) ? nfserr_acces : nfserr_xdev;
 	if (ffhp->fh_export != tfhp->fh_export)
@@ -1710,22 +1708,15 @@ nfsd_rename(struct svc_rqst *rqstp, stru
 			goto out_dput_new;
 	}
 
-	host_err = -EXDEV;
-	if (ffhp->fh_export->ex_path.mnt != tfhp->fh_export->ex_path.mnt)
-		goto out_dput_new;
-	host_err = mnt_want_write(ffhp->fh_export->ex_path.mnt);
-	if (host_err)
-		goto out_dput_new;
-
-	host_err = vfs_rename(fdir, odentry, tdir, ndentry);
+	fh_to_path(ffhp, &old_dir_path);
+	fh_to_path(tfhp, &new_dir_path);
+	host_err = path_rename(&old_dir_path, odentry, &new_dir_path, ndentry);
 	if (!host_err && EX_ISSYNC(tfhp->fh_export)) {
 		host_err = nfsd_sync_dir(tdentry);
 		if (!host_err)
 			host_err = nfsd_sync_dir(fdentry);
 	}
 
-	mnt_drop_write(ffhp->fh_export->ex_path.mnt);
-
  out_dput_new:
 	dput(ndentry);
  out_dput_old:
Index: linux-2.6/include/linux/fs.h
===================================================================
--- linux-2.6.orig/include/linux/fs.h	2008-05-06 11:04:40.000000000 +0200
+++ linux-2.6/include/linux/fs.h	2008-05-06 11:04:41.000000000 +0200
@@ -1131,7 +1131,8 @@ extern int path_symlink(struct path *, s
 extern int path_link(struct dentry *, struct path *, struct dentry *);
 extern int path_rmdir(struct path *, struct dentry *);
 extern int path_unlink(struct path *, struct dentry *);
-extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
+extern int path_rename(struct path *, struct dentry *,
+		       struct path *, struct dentry *);
 
 /*
  * VFS dentry helper functions.

--

  parent reply	other threads:[~2008-05-06  9:22 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-06  9:13 [patch 00/24] vfs: fixes and cleanups + add helpers to check r/o bind mounts Miklos Szeredi
2008-05-06  9:13 ` [patch 01/24] nfsd: clean up mnt_want_write calls Miklos Szeredi
2008-05-06  9:13 ` [patch 02/24] cgroup: dont call vfs_mkdir Miklos Szeredi
2008-05-06  9:13 ` [patch 03/24] reiserfs: dont call vfs_rmdir Miklos Szeredi
2008-05-06  9:13 ` [patch 04/24] reiserfs: dont call notify_change Miklos Szeredi
2008-05-08 16:49   ` Christoph Hellwig
2008-05-06  9:13 ` [patch 05/24] sysfs: " Miklos Szeredi
2008-05-08 16:50   ` Christoph Hellwig
2008-05-06  9:13 ` [patch 06/24] hpfs: " Miklos Szeredi
2008-05-08  0:41   ` Mikulas Patocka
2008-05-08 16:52   ` Christoph Hellwig
2008-05-09  1:59     ` Mikulas Patocka
2008-05-06  9:13 ` [patch 07/24] fat: " Miklos Szeredi
2008-05-08 16:57   ` Christoph Hellwig
2008-05-08 18:51     ` Miklos Szeredi
2008-05-08 19:42     ` OGAWA Hirofumi
2008-05-08 23:45     ` James Morris
2008-05-06  9:13 ` [patch 08/24] vfs: immutable inode checking cleanup Miklos Szeredi
2008-05-15  7:23   ` Al Viro
2008-05-15  7:39     ` Miklos Szeredi
2008-05-06  9:13 ` [patch 09/24] vfs: truncate: dont check immutable twice Miklos Szeredi
2008-05-06  9:13 ` [patch 10/24] vfs: truncate: append-only checking cleanup Miklos Szeredi
2008-05-15  7:49   ` Al Viro
2008-05-15  7:58     ` Miklos Szeredi
2008-05-06  9:13 ` [patch 11/24] vfs: create file_truncate() helper Miklos Szeredi
2008-05-06  9:13 ` [patch 12/24] vfs: utimes immutable fix Miklos Szeredi
2008-05-06  9:13 ` [patch 13/24] vfs: utimes cleanup Miklos Szeredi
2008-05-06 10:03   ` Miklos Szeredi
2008-05-15  7:39     ` Al Viro
2008-05-15  7:45       ` Miklos Szeredi
2008-05-06  9:13 ` [patch 14/24] vfs: splice remove_suid() cleanup Miklos Szeredi
2008-05-06  9:13 ` [patch 15/24] vfs: add path_create() and path_mknod() Miklos Szeredi
2008-05-06  9:13 ` [patch 16/24] vfs: add path_mkdir() Miklos Szeredi
2008-05-06  9:13 ` [patch 17/24] vfs: add path_rmdir() Miklos Szeredi
2008-05-06  9:13 ` [patch 18/24] vfs: add path_unlink() Miklos Szeredi
2008-05-06  9:13 ` [patch 19/24] vfs: add path_symlink() Miklos Szeredi
2008-05-06  9:13 ` [patch 20/24] vfs: add path_link() Miklos Szeredi
2008-05-06  9:13 ` Miklos Szeredi [this message]
2008-05-06  9:13 ` [patch 22/24] vfs: add path_setattr() Miklos Szeredi
2008-05-06  9:13 ` [patch 23/24] vfs: add path_setxattr() Miklos Szeredi
2008-05-06  9:13 ` [patch 24/24] vfs: add path_removexattr() Miklos Szeredi
2008-05-06  9:16 ` [patch 00/24] vfs: fixes and cleanups + add helpers to check r/o bind mounts Christoph Hellwig
2008-05-06 10:33   ` Miklos Szeredi
2008-05-14 14:55     ` Pavel Machek
2008-05-07 11:57 ` Miklos Szeredi

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=20080506091440.391186713@szeredi.hu \
    --to=miklos@szeredi.hu \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).