All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <agruen@suse.de>
To: linux-kernel@vger.kernel.org
Cc: John Johansen <jjohansen@suse.de>, Jan Blunck <jblunck@suse.de>,
	Erez Zadok <ezk@cs.sunysb.edu>,
	"Josef 'Jeff' Sipek" <jsipek@cs.sunysb.edu>
Subject: [RFC 08/10] Pass no NULL vfs_lookup to vfs_create
Date: Wed, 08 Aug 2007 19:16:30 +0200	[thread overview]
Message-ID: <20070808171644.407320917@suse.de> (raw)
In-Reply-To: 20070808171622.632749741@suse.de

[-- Attachment #1: vfs_create-nameidata.diff --]
[-- Type: text/plain, Size: 7865 bytes --]

Never pass a NULL vfs_lookup to vfs_create() or iop->create by creating
temporary vfs_lookup objects where needed. Remove the obsolete NULL
checks.

Signed-off-by: Andreas Gruenbacher <ag@bestbits.at>

---
 fs/9p/vfs_inode.c |    4 ++--
 fs/cifs/dir.c     |    5 ++---
 fs/nfsd/vfs.c     |   36 +++++++++++++++++++++---------------
 ipc/mqueue.c      |   23 ++++++++++++++---------
 4 files changed, 39 insertions(+), 29 deletions(-)

--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -478,7 +478,7 @@ v9fs_vfs_create(struct inode *dir, struc
 	fid = NULL;
 	v9ses = v9fs_inode2v9ses(dir);
 	perm = unixmode2p9mode(v9ses, mode);
-	if (lookup && lookup->flags & LOOKUP_OPEN)
+	if (lookup->flags & LOOKUP_OPEN)
 		flags = lookup->intent.open.flags - 1;
 	else
 		flags = O_RDWR;
@@ -492,7 +492,7 @@ v9fs_vfs_create(struct inode *dir, struc
 	}
 
 	/* if we are opening a file, assign the open fid to the file */
-	if (lookup && lookup->flags & LOOKUP_OPEN) {
+	if (lookup->flags & LOOKUP_OPEN) {
 		filp = lookup_instantiate_filp(lookup, dentry,
 					       v9fs_open_created);
 		if (IS_ERR(filp)) {
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -153,7 +153,7 @@ cifs_create(struct inode *inode, struct 
 		return -ENOMEM;
 	}
 
-	if (lookup && (lookup->flags & LOOKUP_OPEN)) {
+	if (lookup->flags & LOOKUP_OPEN) {
 		int oflags = lookup->intent.open.flags;
 
 		desiredAccess = 0;
@@ -263,8 +263,7 @@ cifs_create(struct inode *inode, struct 
 				direntry->d_op = &cifs_dentry_ops;
 			d_instantiate(direntry, newinode);
 		}
-		if ((!lookup /* nfsd case - nfs srv does not set lookup */) ||
-			((lookup->flags & LOOKUP_OPEN) == FALSE)) {
+		if (!(lookup->flags & LOOKUP_OPEN)) {
 			/* mknod case - do not leave file open */
 			CIFSSMBClose(xid, pTcon, fileHandle);
 		} else if (newinode) {
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1139,7 +1139,8 @@ nfsd_create(struct svc_rqst *rqstp, stru
 		char *fname, int flen, struct iattr *iap,
 		int type, dev_t rdev, struct svc_fh *resfhp)
 {
-	struct dentry	*dentry, *dchild = NULL;
+	struct vfs_lookup lookup;
+	struct dentry	*dchild = NULL;
 	struct inode	*dirp;
 	__be32		err;
 	int		host_err;
@@ -1155,8 +1156,10 @@ nfsd_create(struct svc_rqst *rqstp, stru
 	if (err)
 		goto out;
 
-	dentry = fhp->fh_dentry;
-	dirp = dentry->d_inode;
+	lookup.path.dentry = fhp->fh_dentry;
+	lookup.path.mnt = fhp->fh_export->ex_mnt;
+	lookup.flags = 0;
+	dirp = lookup.path.dentry->d_inode;
 
 	err = nfserr_notdir;
 	if(!dirp->i_op || !dirp->i_op->lookup)
@@ -1168,7 +1171,7 @@ nfsd_create(struct svc_rqst *rqstp, stru
 	if (!resfhp->fh_dentry) {
 		/* called from nfsd_proc_mkdir, or possibly nfsd3_proc_create */
 		fh_lock_nested(fhp, I_MUTEX_PARENT);
-		dchild = lookup_one_len(fname, dentry, flen);
+		dchild = lookup_one_len(fname, lookup.path.dentry, flen);
 		host_err = PTR_ERR(dchild);
 		if (IS_ERR(dchild))
 			goto out_nfserr;
@@ -1182,8 +1185,8 @@ nfsd_create(struct svc_rqst *rqstp, stru
 			/* not actually possible */
 			printk(KERN_ERR
 				"nfsd_create: parent %s/%s not locked!\n",
-				dentry->d_parent->d_name.name,
-				dentry->d_name.name);
+				lookup.path.dentry->d_parent->d_name.name,
+				lookup.path.dentry->d_name.name);
 			err = nfserr_io;
 			goto out;
 		}
@@ -1194,7 +1197,7 @@ nfsd_create(struct svc_rqst *rqstp, stru
 	err = nfserr_exist;
 	if (dchild->d_inode) {
 		dprintk("nfsd_create: dentry %s/%s not negative!\n",
-			dentry->d_name.name, dchild->d_name.name);
+			lookup.path.dentry->d_name.name, dchild->d_name.name);
 		goto out; 
 	}
 
@@ -1208,7 +1211,7 @@ nfsd_create(struct svc_rqst *rqstp, stru
 	err = 0;
 	switch (type) {
 	case S_IFREG:
-		host_err = vfs_create(dirp, dchild, iap->ia_mode, NULL);
+		host_err = vfs_create(dirp, dchild, iap->ia_mode, &lookup);
 		break;
 	case S_IFDIR:
 		host_err = vfs_mkdir(dirp, dchild, iap->ia_mode);
@@ -1227,7 +1230,7 @@ nfsd_create(struct svc_rqst *rqstp, stru
 		goto out_nfserr;
 
 	if (EX_ISSYNC(fhp->fh_export)) {
-		err = nfserrno(nfsd_sync_dir(dentry));
+		err = nfserrno(nfsd_sync_dir(lookup.path.dentry));
 		write_inode_now(dchild->d_inode, 1);
 	}
 
@@ -1267,7 +1270,8 @@ nfsd_create_v3(struct svc_rqst *rqstp, s
 		struct svc_fh *resfhp, int createmode, u32 *verifier,
 	        int *truncp, int *created)
 {
-	struct dentry	*dentry, *dchild = NULL;
+	struct vfs_lookup lookup;
+	struct dentry	*dchild = NULL;
 	struct inode	*dirp;
 	__be32		err;
 	int		host_err;
@@ -1285,8 +1289,10 @@ nfsd_create_v3(struct svc_rqst *rqstp, s
 	if (err)
 		goto out;
 
-	dentry = fhp->fh_dentry;
-	dirp = dentry->d_inode;
+	lookup.path.dentry = fhp->fh_dentry;
+	lookup.path.mnt = fhp->fh_export->ex_mnt;
+	lookup.flags = 0;
+	dirp = lookup.path.dentry->d_inode;
 
 	/* Get all the sanity checks out of the way before
 	 * we lock the parent. */
@@ -1298,7 +1304,7 @@ nfsd_create_v3(struct svc_rqst *rqstp, s
 	/*
 	 * Compose the response file handle.
 	 */
-	dchild = lookup_one_len(fname, dentry, flen);
+	dchild = lookup_one_len(fname, lookup.path.dentry, flen);
 	host_err = PTR_ERR(dchild);
 	if (IS_ERR(dchild))
 		goto out_nfserr;
@@ -1352,14 +1358,14 @@ nfsd_create_v3(struct svc_rqst *rqstp, s
 		goto out;
 	}
 
-	host_err = vfs_create(dirp, dchild, iap->ia_mode, NULL);
+	host_err = vfs_create(dirp, dchild, iap->ia_mode, &lookup);
 	if (host_err < 0)
 		goto out_nfserr;
 	if (created)
 		*created = 1;
 
 	if (EX_ISSYNC(fhp->fh_export)) {
-		err = nfserrno(nfsd_sync_dir(dentry));
+		err = nfserrno(nfsd_sync_dir(lookup.path.dentry));
 		/* setattr will sync the child (or not) */
 	}
 
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -599,9 +599,11 @@ static int mq_attr_ok(struct mq_attr *at
 /*
  * Invoked when creating a new queue via sys_mq_open
  */
-static struct file *do_create(struct dentry *dir, struct dentry *dentry,
-			int oflag, mode_t mode, struct mq_attr __user *u_attr)
+static struct file *do_create(struct vfs_lookup *lookup, int oflag, mode_t mode,
+			      struct mq_attr __user *u_attr)
 {
+	struct dentry *dir = mqueue_mnt->mnt_root;
+	struct dentry *dentry = lookup->path.dentry;
 	struct mq_attr attr;
 	int ret;
 
@@ -617,7 +619,7 @@ static struct file *do_create(struct den
 	}
 
 	mode &= ~current->fs->umask;
-	ret = vfs_create(dir->d_inode, dentry, mode, NULL);
+	ret = vfs_create(dir->d_inode, dentry, mode, lookup);
 	dentry->d_fsdata = NULL;
 	if (ret)
 		goto out;
@@ -631,10 +633,11 @@ out:
 }
 
 /* Opens existing queue */
-static struct file *do_open(struct dentry *dentry, int oflag)
+static struct file *do_open(struct vfs_lookup *lookup, int oflag)
 {
 static int oflag2acc[O_ACCMODE] = { MAY_READ, MAY_WRITE,
 					MAY_READ | MAY_WRITE };
+	struct dentry *dentry = lookup->path.dentry;
 
 	if ((oflag & O_ACCMODE) == (O_RDWR | O_WRONLY)) {
 		dput(dentry);
@@ -654,6 +657,7 @@ static int oflag2acc[O_ACCMODE] = { MAY_
 asmlinkage long sys_mq_open(const char __user *u_name, int oflag, mode_t mode,
 				struct mq_attr __user *u_attr)
 {
+	struct vfs_lookup lookup;
 	struct dentry *dentry;
 	struct file *filp;
 	char *name;
@@ -676,7 +680,9 @@ asmlinkage long sys_mq_open(const char _
 		error = PTR_ERR(dentry);
 		goto out_err;
 	}
-	mntget(mqueue_mnt);
+	lookup.path.mnt = mntget(mqueue_mnt);
+	lookup.path.dentry = dentry;
+	lookup.flags = 0;
 
 	if (oflag & O_CREAT) {
 		if (dentry->d_inode) {	/* entry already exists */
@@ -684,17 +690,16 @@ asmlinkage long sys_mq_open(const char _
 			error = -EEXIST;
 			if (oflag & O_EXCL)
 				goto out;
-			filp = do_open(dentry, oflag);
+			filp = do_open(&lookup, oflag);
 		} else {
-			filp = do_create(mqueue_mnt->mnt_root, dentry,
-						oflag, mode, u_attr);
+			filp = do_create(&lookup, oflag, mode, u_attr);
 		}
 	} else {
 		error = -ENOENT;
 		if (!dentry->d_inode)
 			goto out;
 		audit_inode(name, dentry->d_inode);
-		filp = do_open(dentry, oflag);
+		filp = do_open(&lookup, oflag);
 	}
 
 	if (IS_ERR(filp)) {


  parent reply	other threads:[~2007-08-08 17:22 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-08 17:16 [RFC 00/10] Split up struct nameidata (take 3) Andreas Gruenbacher
2007-08-08 17:16 ` [RFC 01/10] Split up struct nameidata Andreas Gruenbacher
2007-08-08 19:32   ` Christoph Hellwig
2007-08-09  8:26     ` atomic open (was Re: [RFC 01/10] Split up struct nameidata) Miklos Szeredi
2007-08-10 14:42     ` [RFC 01/10] Split up struct nameidata Andreas Gruenbacher
2007-08-10 14:22       ` [patch 1/4] Introduce pathput Andreas Gruenbacher
2007-08-29 19:07         ` Christoph Hellwig
2007-09-14 16:36           ` Christoph Hellwig
2007-08-10 14:22       ` [patch 2/4] Use pathput in a few more places Andreas Gruenbacher
2007-08-29 19:08         ` Christoph Hellwig
2007-08-30 15:01           ` [FIX] mntput called before dput in afs Andreas Gruenbacher
2007-08-30 15:15             ` David Howells
2007-08-30 15:56             ` David Howells
2007-08-10 14:22       ` [patch 3/4] Introduce pathget Andreas Gruenbacher
2007-08-29 19:09         ` Christoph Hellwig
2007-08-10 14:22       ` [patch 4/4] Switch to struct path in fs_struct Andreas Gruenbacher
2007-08-29 19:12         ` Christoph Hellwig
2007-08-08 17:16 ` [RFC 02/10] Switch from nd->{mnt,dentry} to nd->lookup.path.{mnt,dentry} Andreas Gruenbacher
2007-08-08 17:16 ` [RFC 03/10] Pass no unnecessary information to iop->permission Andreas Gruenbacher
2007-08-08 17:16 ` [RFC 04/10] Temporary struct vfs_lookup in file_permission Andreas Gruenbacher
2007-08-08 17:58   ` Josef Sipek
2007-08-08 18:56     ` Andreas Gruenbacher
2007-08-08 19:25   ` Christoph Hellwig
2007-08-08 21:41     ` Andreas Gruenbacher
2007-08-08 23:24       ` Christoph Hellwig
2007-08-09 17:23         ` Andreas Gruenbacher
2007-08-08 17:16 ` [RFC 05/10] Use vfs_permission instead of file_permission in sys_fchdir Andreas Gruenbacher
2007-08-08 19:26   ` Christoph Hellwig
2007-08-08 17:16 ` [RFC 06/10] Use vfs_permission instead of file_permission in do_path_lookup Andreas Gruenbacher
2007-08-08 19:27   ` Christoph Hellwig
2007-08-08 17:16 ` [RFC 07/10] Pass no unnecessary information to iop->create Andreas Gruenbacher
2007-08-08 17:16 ` Andreas Gruenbacher [this message]
2007-08-08 19:36   ` [RFC 08/10] Pass no NULL vfs_lookup to vfs_create Christoph Hellwig
2007-08-08 17:16 ` [RFC 09/10] Pass no unnecessary information to dop->d_revalidate Andreas Gruenbacher
2007-08-08 17:16 ` [RFC 10/10] Pass no unnecessary information to iop->lookup Andreas Gruenbacher

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=20070808171644.407320917@suse.de \
    --to=agruen@suse.de \
    --cc=ezk@cs.sunysb.edu \
    --cc=jblunck@suse.de \
    --cc=jjohansen@suse.de \
    --cc=jsipek@cs.sunysb.edu \
    --cc=linux-kernel@vger.kernel.org \
    /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.