VFS/nfsd: replace dentry_create()
Subsystems (3)
cover VFS/nfsd: replace dentry_create()
My recent proposal for inverting the order between inode_lock() on a parent dir and d_alloc_parallel()[1] missed that fact that atomic_open() has two callers, and would have resulted in easy deadlocks from nfsd when re-exporting and NFS filesystem.
I think the best way to fix this is to provide a richer interface for nfsd to use, which includes all the locking as well as inode_operations calls. This allows the nfsd behaviour to share more code with the system-call behaviour.
This series refactors code between lookup_open() and open_last_lookups(), and uses the new lookup_open() to provide vfs_lookup_open(). It then rearranges the code in nfsd so that it can easily use vfs_lookup_open() instead of dentry_create(). Finally dentry_create() is removed.
This series is based on a merge of nfsd-testing, vfs-next/work.dcache, and vfs/vfs.fixes (though I can't see my "Fix possible failure to unlock.."[2] patch in there yet). So I probably will need to resubmit after a bunch of that has hit mainline - though a few of the patches could easily be cherry-picked now.
This will conflict with the O_CREAT|O_DIRECTORY work so obviously we'll need to work out how to order them once we both have enough positive review.
All these patches are in github/neilbrown/linux in branch pdirops. You can also preview the other stuff I need this for in pdirops-next.
Please review if you have time.
Thanks,
NeilBrown
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[PATCH 01/18] VFS: move mnt_want_write() and locking into [PATCH 02/18] VFS: move delegated_inode retry loop into lookup_open() [PATCH 03/18] VFS: replace nameidata and open_flag args to [PATCH 04/18] VFS: add vfs_lookup_open()
[PATCH 05/18] VFS: dentry_create: always set FMODE_CREATE when file [PATCH 06/18] nfsd: replace fh_fill_both_attrs() with [PATCH 07/18] nfsd: move fh_want_write() after preamble in [PATCH 08/18] nfsd: move more nfs-specific code into preamble of [PATCH 09/18] nfsd: remove subtlety from nfsd4_create_file() [PATCH 10/18] nfsd: in nfsd4_create_file() let VFS report if file was [PATCH 11/18] nfsd: nfsd4_create_file(): remove NFSD_MAY_CREATE [PATCH 12/18] nfsd: reduce range of directory lock in [PATCH 13/18] nfsd: open-code nfsd4_vfs_create() into [PATCH 14/18] nfsd: move some code out of the d_really_is_negative() [PATCH 15/18] nfsd: reduce want-write range in nfsd4_create_file( [PATCH 16/18] nfsd: switch nfsd4_create_file() to use [PATCH 17/18] nfsd: use vfs_lookup_open() for non-creating open [PATCH 18/18] VFS: remove dentry_create()
PATCH 1/18 VFS: move mnt_want_write() and locking into lookup_open()
From: NeilBrown <[email protected]>
The mnt_want_write() call and the parent inode locking in open_last_lookups() are only needed for lookup_open(). So we can move them and all the got_write handling into lookup_open().
Note that we need to also check create_error when determining whether to unlock shared or not, as O_CREAT can be cleared.
The fsnotify calls come too as they must be in the locked region.
Also use the existing dir_inode uniformly for dir->d_inode.
This is a step towards exporting an better "open/create" interface to nfsd.
--- fs/namei.c | 77 +++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 36 deletions(-)
fs/namei.c +41 -36
@@ -4404,7 +4404,7 @@ static struct dentry *atomic_open(const struct path *path, struct dentry *dentry*/ static struct dentry *lookup_open (struct nameidata *nd,struct file *file,const struct open_flags *op, -bool got_write,struct delegated_inode *delegated_inode) +struct delegated_inode *delegated_inode) {struct mnt_idmap *idmap;struct dentry *dir = nd->path.dentry;
@@ -4413,9 +4413,25 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,struct dentry *dentry;int error, create_error =0 ;umode_t mode = op->mode; +bool got_write = false; -if (unlikely (IS_DEADDIR (dir_inode))) -return ERR_PTR (-ENOENT ); +if (open_flag & (O_CREAT |O_TRUNC |O_WRONLY |O_RDWR )) { + got_write = !mnt_want_write (nd->path.mnt); +/* +* do _not_ fail yet - we might not need that or fail with +* a different error; let lookup_open() decide; we'll be +* dropping this one anyway. +*/ + } +if (open_flag &O_CREAT ) +inode_lock (dir_inode); +else +inode_lock_shared (dir_inode); + +if (unlikely (IS_DEADDIR (dir_inode))) { + dentry =ERR_PTR (-ENOENT ); + goto out; + } file->f_mode &= ~FMODE_CREATED ; dentry =d_lookup (dir, &nd->last);
@@ -4423,7 +4439,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,if (!dentry) { dentry =d_alloc_parallel (dir, &nd->last);if (IS_ERR (dentry)) -return dentry; + goto out; }if (d_in_lookup (dentry))break ;
@@ -4439,7 +4455,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, }if (dentry->d_inode) {/* Cached positive dentry: will open in f_op->open */ -return dentry; + goto out; }if (open_flag &O_CREAT )
@@ -4460,7 +4476,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,if (open_flag &O_CREAT ) {if (open_flag &O_EXCL ) open_flag &= ~O_TRUNC ; - mode =vfs_prepare_mode (idmap, dir->d_inode, mode, mode, mode); + mode =vfs_prepare_mode (idmap, dir_inode, mode, mode, mode);if (likely (got_write)) create_error =may_o_create (idmap, &nd->path, dentry, mode);
@@ -4475,7 +4491,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, dentry =atomic_open (&nd->path, dentry, file, open_flag, mode);if (unlikely (create_error) && dentry ==ERR_PTR (-ENOENT )) dentry =ERR_PTR (create_error); -return dentry; + goto out; }if (d_in_lookup (dentry)) {
@@ -4515,11 +4531,27 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, error = create_error; goto out_dput; } +out: +if (!IS_ERR (dentry)) { +if (file->f_mode &FMODE_CREATED ) +fsnotify_create (dir_inode, dentry); +if (file->f_mode &FMODE_OPENED ) +fsnotify_open (file); + } +if ((open_flag &O_CREAT ) || create_error) +inode_unlock (dir_inode); +else +inode_unlock_shared (dir_inode); + +if (got_write) +mnt_drop_write (nd->path.mnt); +return dentry; out_dput:dput (dentry); -return ERR_PTR (error); + dentry =ERR_PTR (error); + goto out; }static inline bool trailing_slashes (struct nameidata *nd)
@@ -4562,9 +4594,7 @@ static const char *open_last_lookups(struct nameidata *nd, struct file *file, const struct open_flags *op) { struct delegated_inode delegated_inode = { }; -struct dentry *dir = nd->path.dentry;int open_flag = op->open_flag; -bool got_write = false;struct dentry *dentry;const char *res;
@@ -4594,32 +4624,7 @@ static const char *open_last_lookups(struct nameidata *nd, } } retry: -if (open_flag & (O_CREAT |O_TRUNC |O_WRONLY |O_RDWR )) { - got_write = !mnt_want_write (nd->path.mnt); -/* -* do _not_ fail yet - we might not need that or fail with -* a different error; let lookup_open() decide; we'll be -* dropping this one anyway. -*/ - } -if (open_flag &O_CREAT ) -inode_lock (dir->d_inode); -else -inode_lock_shared (dir->d_inode); - dentry =lookup_open (nd, file, op, got_write, &delegated_inode); -if (!IS_ERR (dentry)) { -if (file->f_mode &FMODE_CREATED ) -fsnotify_create (dir->d_inode, dentry); -if (file->f_mode &FMODE_OPENED ) -fsnotify_open (file); - } -if (open_flag &O_CREAT ) -inode_unlock (dir->d_inode); -else -inode_unlock_shared (dir->d_inode); - -if (got_write) -mnt_drop_write (nd->path.mnt); + dentry =lookup_open (nd, file, op, &delegated_inode);if (IS_ERR (dentry)) {if (is_delegated (&delegated_inode)) {
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
Re: [PATCH 01/18] VFS: move mnt_want_write() and locking into lookup_open()
Quoted 21 lines
Op 01-06-2026 08:37 CEST schreef NeilBrown <[email protected]>:
From: NeilBrown <[email protected]>
The
mnt_want_write()call and the parent inode locking inopen_last_lookups()are only needed forlookup_open(). So we can move them and all thegot_writehandling intolookup_open().Note that we need to also check
create_errorwhen determining whether to unlock shared or not, asO_CREATcan be cleared.The fsnotify calls come too as they must be in the locked region.
Also use the existing
dir_inodeuniformly fordir->d_inode.This is a step towards exporting an better "open/create" interface to nfsd.
Signed-off-by NeilBrown <[email protected]>---
fs/namei.c static struct dentry *lookup_open(struct nameidata *nd, struct file *file, · line 4430
Quoted 5 lines
fs/namei.c +5
-0+if (open_flag &O_CREAT ) +inode_lock (dir_inode); +else +inode_lock_shared (dir_inode); +
This is not about a change in your patch, but I do wonder whether we should also set the lockdep subclass here. We aren't taking any other locks, but that is also true in the create path of mknod, which ultimately calls start_dirop and there we do
inode_lock_nested(dir, I_MUTEX_PARENT);
Quoted 44 lines
fs/namei.c +8
-4+if (unlikely (IS_DEADDIR (dir_inode))) { + dentry =ERR_PTR (-ENOENT ); + goto out; + } file->f_mode &= ~FMODE_CREATED ; dentry =d_lookup (dir, &nd->last);@@ -4423,7 +4439,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,if (!dentry) { dentry =d_alloc_parallel (dir, &nd->last);if (IS_ERR (dentry)) -return dentry; + goto out; }if (d_in_lookup (dentry))break ;@@ -4439,7 +4455,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, }if (dentry->d_inode) {/* Cached positive dentry: will open in f_op->open */ -return dentry; + goto out; }if (open_flag &O_CREAT )@@ -4460,7 +4476,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,if (open_flag &O_CREAT ) {if (open_flag &O_EXCL ) open_flag &= ~O_TRUNC ; - mode =vfs_prepare_mode (idmap, dir->d_inode, mode, mode, mode); + mode =vfs_prepare_mode (idmap, dir_inode, mode, mode, mode);if (likely (got_write)) create_error =may_o_create (idmap, &nd->path, dentry, mode);@@ -4475,7 +4491,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, dentry =atomic_open (&nd->path, dentry, file, open_flag, mode);if (unlikely (create_error) && dentry ==ERR_PTR (-ENOENT )) dentry =ERR_PTR (create_error); -return dentry; + goto out; }if (d_in_lookup (dentry)) {
fs/namei.c static struct dentry *lookup_open(struct nameidata *nd, struct file *file, · line 4540
Quoted 10 lines
fs/namei.c +7
-0@@ -4515,11 +4531,27 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, error = create_error; goto out_dput; } +out: +if (!IS_ERR (dentry)) { +if (file->f_mode &FMODE_CREATED ) +fsnotify_create (dir_inode, dentry); +if (file->f_mode &FMODE_OPENED ) +fsnotify_open (file); + }
We can move this later if my changes land to the vfs_* and atomic_open() functions.
Quoted 64 lines
fs/namei.c +11
-29+if ((open_flag &O_CREAT ) || create_error) +inode_unlock (dir_inode); +else +inode_unlock_shared (dir_inode); + +if (got_write) +mnt_drop_write (nd->path.mnt); +return dentry; out_dput:dput (dentry); -return ERR_PTR (error); + dentry =ERR_PTR (error); + goto out; }static inline bool trailing_slashes (struct nameidata *nd)@@ -4562,9 +4594,7 @@ static const char *open_last_lookups(struct nameidata *nd, struct file *file, const struct open_flags *op) { struct delegated_inode delegated_inode = { }; -struct dentry *dir = nd->path.dentry;int open_flag = op->open_flag; -bool got_write = false;struct dentry *dentry;const char *res;@@ -4594,32 +4624,7 @@ static const char *open_last_lookups(struct nameidata *nd, } } retry: -if (open_flag & (O_CREAT |O_TRUNC |O_WRONLY |O_RDWR )) { - got_write = !mnt_want_write (nd->path.mnt); -/* -* do _not_ fail yet - we might not need that or fail with -* a different error; let lookup_open() decide; we'll be -* dropping this one anyway. -*/ - } -if (open_flag &O_CREAT ) -inode_lock (dir->d_inode); -else -inode_lock_shared (dir->d_inode); - dentry =lookup_open (nd, file, op, got_write, &delegated_inode); -if (!IS_ERR (dentry)) { -if (file->f_mode &FMODE_CREATED ) -fsnotify_create (dir->d_inode, dentry); -if (file->f_mode &FMODE_OPENED ) -fsnotify_open (file); - } -if (open_flag &O_CREAT ) -inode_unlock (dir->d_inode); -else -inode_unlock_shared (dir->d_inode); - -if (got_write) -mnt_drop_write (nd->path.mnt); + dentry =lookup_open (nd, file, op, &delegated_inode);if (IS_ERR (dentry)) {if (is_delegated (&delegated_inode)) {Signature · 1 line
2.50.0.107.gf914562f5916.dirty
I will say we are doing a lot in lookup_open(), but since open_last_lookups() is its only caller, and there is no particular reason that I see for doing this work there, this is fine by me if it helps your nfsd refactor.
PATCH 2/18 VFS: move delegated_inode retry loop into lookup_open()
In reply to NeilBrownFrom: NeilBrown <[email protected]>
By moving this retry into lookup_open() we no longer need to pass around the delegated_inode pointer.
Various variable assignments need to be moved out of the declaration block so that they can still happen after the goto.
--- fs/namei.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-)
fs/namei.c +23 -19
@@ -4403,17 +4403,23 @@ static struct dentry *atomic_open(const struct path *path, struct dentry *dentry* An error code is returned on failure. */ static struct dentry *lookup_open (struct nameidata *nd,struct file *file, -const struct open_flags *op, -struct delegated_inode *delegated_inode) +const struct open_flags *op) { +struct delegated_inode delegated_inode = { };struct mnt_idmap *idmap;struct dentry *dir = nd->path.dentry;struct inode *dir_inode = dir->d_inode; -int open_flag = op->open_flag; +int open_flag;struct dentry *dentry; -int error, create_error =0 ; -umode_t mode = op->mode; -bool got_write = false; +int error, create_error; +umode_t mode; +bool got_write; + +retry: + open_flag = op->open_flag; + got_write = false; + mode = op->mode; + create_error =0 ;if (open_flag & (O_CREAT |O_TRUNC |O_WRONLY |O_RDWR )) { got_write = !mnt_want_write (nd->path.mnt);
@@ -4511,7 +4517,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,/* Negative dentry, just create the file */ if (!dentry->d_inode && (open_flag &O_CREAT )) {/* but break the directory lease first! */ - error =try_break_deleg (dir_inode,LEASE_BREAK_DIR_CREATE , delegated_inode); + error =try_break_deleg (dir_inode,LEASE_BREAK_DIR_CREATE , &delegated_inode);if (error) goto out_dput;
@@ -4546,6 +4552,14 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,if (got_write)mnt_drop_write (nd->path.mnt); +if (is_delegated (&delegated_inode)) { +/* Must have come through out_dput */ + error =break_deleg_wait (&delegated_inode); + +if (!error) + goto retry; + } +return dentry; out_dput:
@@ -4593,7 +4607,6 @@ static struct dentry *lookup_fast_for_open(struct nameidata *nd, int open_flag)static const char *open_last_lookups (struct nameidata *nd,struct file *file,const struct open_flags *op) { -struct delegated_inode delegated_inode = { };int open_flag = op->open_flag;struct dentry *dentry;const char *res;
@@ -4623,19 +4636,10 @@ static const char *open_last_lookups(struct nameidata *nd,return ERR_PTR (-ECHILD ); } } -retry: - dentry =lookup_open (nd, file, op, &delegated_inode); - -if (IS_ERR (dentry)) { -if (is_delegated (&delegated_inode)) { -int error =break_deleg_wait (&delegated_inode); -if (!error) - goto retry; -return ERR_PTR (error); - } + dentry =lookup_open (nd, file, op); +if (IS_ERR (dentry))return ERR_CAST (dentry); - }if (file->f_mode & (FMODE_OPENED |FMODE_CREATED )) {dput (nd->path.dentry);
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
Re: [PATCH 02/18] VFS: move delegated_inode retry loop into lookup_open()
Quoted 107 lines
Op 01-06-2026 08:37 CEST schreef NeilBrown <[email protected]>:
From: NeilBrown <[email protected]>
By moving this retry into
lookup_open()we no longer need to pass around thedelegated_inodepointer.Various variable assignments need to be moved out of the declaration block so that they can still happen after the goto.
Signed-off-by NeilBrown <[email protected]>--- fs/namei.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-)fs/namei.c +23
-19@@ -4403,17 +4403,23 @@ static struct dentry *atomic_open(const struct path *path, struct dentry *dentry* An error code is returned on failure. */ static struct dentry *lookup_open (struct nameidata *nd,struct file *file, -const struct open_flags *op, -struct delegated_inode *delegated_inode) +const struct open_flags *op) { +struct delegated_inode delegated_inode = { };struct mnt_idmap *idmap;struct dentry *dir = nd->path.dentry;struct inode *dir_inode = dir->d_inode; -int open_flag = op->open_flag; +int open_flag;struct dentry *dentry; -int error, create_error =0 ; -umode_t mode = op->mode; -bool got_write = false; +int error, create_error; +umode_t mode; +bool got_write; + +retry: + open_flag = op->open_flag; + got_write = false; + mode = op->mode; + create_error =0 ;if (open_flag & (O_CREAT |O_TRUNC |O_WRONLY |O_RDWR )) { got_write = !mnt_want_write (nd->path.mnt);@@ -4511,7 +4517,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,/* Negative dentry, just create the file */ if (!dentry->d_inode && (open_flag &O_CREAT )) {/* but break the directory lease first! */ - error =try_break_deleg (dir_inode,LEASE_BREAK_DIR_CREATE , delegated_inode); + error =try_break_deleg (dir_inode,LEASE_BREAK_DIR_CREATE , &delegated_inode);if (error) goto out_dput;@@ -4546,6 +4552,14 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,if (got_write)mnt_drop_write (nd->path.mnt); +if (is_delegated (&delegated_inode)) { +/* Must have come through out_dput */ + error =break_deleg_wait (&delegated_inode); + +if (!error) + goto retry; + } +return dentry; out_dput:@@ -4593,7 +4607,6 @@ static struct dentry *lookup_fast_for_open(struct nameidata *nd, int open_flag)static const char *open_last_lookups (struct nameidata *nd,struct file *file,const struct open_flags *op) { -struct delegated_inode delegated_inode = { };int open_flag = op->open_flag;struct dentry *dentry;const char *res;@@ -4623,19 +4636,10 @@ static const char *open_last_lookups(struct nameidata *nd,return ERR_PTR (-ECHILD ); } } -retry: - dentry =lookup_open (nd, file, op, &delegated_inode); - -if (IS_ERR (dentry)) { -if (is_delegated (&delegated_inode)) { -int error =break_deleg_wait (&delegated_inode); -if (!error) - goto retry; -return ERR_PTR (error); - } + dentry =lookup_open (nd, file, op); +if (IS_ERR (dentry))return ERR_CAST (dentry); - }if (file->f_mode & (FMODE_OPENED |FMODE_CREATED )) {dput (nd->path.dentry);Signature · 1 line
2.50.0.107.gf914562f5916.dirty
It does make sense to me that we deal with the retry-loop in the function where we call try_break_deleg(). That part is then dealt with on return to open_last_lookups(). So I think, at least from a cognitive load perspective, this change makes sense.
PATCH 3/18 VFS: replace nameidata and open_flag args to lookup_open()
In reply to NeilBrownFrom: NeilBrown <[email protected]>
lookup_open is currently given "struct nameiodata" and "struct open_flag" pointer args. These structures are internal to VFS. Replace these with the individual fields that lookup_open() actually needs. This will allow it be exported so it can be used to replace dentry_create().
As lookup_open() can change both open_flag and mode, we keep the local variable and create an arg with a different name which is assigned to the local variable.
--- fs/namei.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-)
fs/namei.c +21 -17
@@ -4402,12 +4402,15 @@ static struct dentry *atomic_open(const struct path *path, struct dentry *dentry* * An error code is returned on failure. */ -static struct dentry *lookup_open (struct nameidata *nd,struct file *file, -const struct open_flags *op) +static struct dentry *lookup_open (const struct path *path,struct file *file, +const struct qstr *last, +unsigned int lookup_flags, +struct filename *name, +int open_flag_arg,umode_t mode_arg) {struct delegated_inode delegated_inode = { };struct mnt_idmap *idmap; -struct dentry *dir = nd->path.dentry; +struct dentry *dir = path->dentry;struct inode *dir_inode = dir->d_inode;int open_flag;struct dentry *dentry;
@@ -4416,13 +4419,13 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,bool got_write; retry: - open_flag = op->open_flag; + open_flag = open_flag_arg; got_write = false; - mode = op->mode; + mode = mode_arg; create_error =0 ;if (open_flag & (O_CREAT |O_TRUNC |O_WRONLY |O_RDWR )) { - got_write = !mnt_want_write (nd->path.mnt); + got_write = !mnt_want_write (path->mnt);/* * do _not_ fail yet - we might not need that or fail with * a different error; let lookup_open() decide; we'll be
@@ -4440,17 +4443,17 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, } file->f_mode &= ~FMODE_CREATED ; - dentry =d_lookup (dir, &nd->last); + dentry =d_lookup (dir, last);for (;;) {if (!dentry) { - dentry =d_alloc_parallel (dir, &nd->last); + dentry =d_alloc_parallel (dir, last);if (IS_ERR (dentry)) goto out; }if (d_in_lookup (dentry))break ; - error =d_revalidate (dir_inode, &nd->last, dentry, nd->flags); + error =d_revalidate (dir_inode, last, dentry, lookup_flags);if (likely (error >0 ))break ;if (error)
@@ -4465,7 +4468,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, }if (open_flag &O_CREAT ) -audit_inode (nd->name, dir,AUDIT_INODE_PARENT ); +audit_inode (name, dir,AUDIT_INODE_PARENT );/* * Checking write permission is tricky, bacuse we don't know if we are
@@ -4478,13 +4481,13 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,*/ if (unlikely (!got_write)) open_flag &= ~O_TRUNC ; - idmap =mnt_idmap (nd->path.mnt); + idmap =mnt_idmap (path->mnt);if (open_flag &O_CREAT ) {if (open_flag &O_EXCL ) open_flag &= ~O_TRUNC ; mode =vfs_prepare_mode (idmap, dir_inode, mode, mode, mode);if (likely (got_write)) - create_error =may_o_create (idmap, &nd->path, + create_error =may_o_create (idmap, path, dentry, mode);else create_error = -EROFS ;
@@ -4492,9 +4495,9 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,if (create_error) open_flag &= ~O_CREAT ;if (dir_inode->i_op->atomic_open) { -if (nd->flags &LOOKUP_DIRECTORY ) +if (lookup_flags &LOOKUP_DIRECTORY ) open_flag |=O_DIRECTORY ; - dentry =atomic_open (&nd->path, dentry, file, open_flag, mode); + dentry =atomic_open (path, dentry, file, open_flag, mode);if (unlikely (create_error) && dentry ==ERR_PTR (-ENOENT )) dentry =ERR_PTR (create_error); goto out;
@@ -4502,7 +4505,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,if (d_in_lookup (dentry)) {struct dentry *res = dir_inode->i_op->lookup (dir_inode, dentry, - nd->flags); + lookup_flags);d_lookup_done (dentry);if (unlikely (res)) {if (IS_ERR (res)) {
@@ -4550,7 +4553,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,inode_unlock_shared (dir_inode);if (got_write) -mnt_drop_write (nd->path.mnt); +mnt_drop_write (path->mnt);if (is_delegated (&delegated_inode)) {/* Must have come through out_dput */
@@ -4637,7 +4640,8 @@ static const char *open_last_lookups(struct nameidata *nd, } } - dentry =lookup_open (nd, file, op); + dentry =lookup_open (&nd->path, file, &nd->last, + nd->flags, nd->name, op->open_flag, op->mode);if (IS_ERR (dentry))return ERR_CAST (dentry);
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
Re: [PATCH 03/18] VFS: replace nameidata and open_flag args to lookup_open()
Quoted 149 lines
Op 01-06-2026 08:37 CEST schreef NeilBrown <[email protected]>:
From: NeilBrown <[email protected]>
lookup_openis currently given "struct nameiodata" and "structopen_flag" pointer args. These structures are internal to VFS. Replace these with the individual fields thatlookup_open()actually needs. This will allow it be exported so it can be used to replacedentry_create().As
lookup_open()can change bothopen_flagand mode, we keep the local variable and create an arg with a different name which is assigned to the local variable.Signed-off-by NeilBrown <[email protected]>--- fs/namei.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-)fs/namei.c +21
-17@@ -4402,12 +4402,15 @@ static struct dentry *atomic_open(const struct path *path, struct dentry *dentry* * An error code is returned on failure. */ -static struct dentry *lookup_open (struct nameidata *nd,struct file *file, -const struct open_flags *op) +static struct dentry *lookup_open (const struct path *path,struct file *file, +const struct qstr *last, +unsigned int lookup_flags, +struct filename *name, +int open_flag_arg,umode_t mode_arg) {struct delegated_inode delegated_inode = { };struct mnt_idmap *idmap; -struct dentry *dir = nd->path.dentry; +struct dentry *dir = path->dentry;struct inode *dir_inode = dir->d_inode;int open_flag;struct dentry *dentry;@@ -4416,13 +4419,13 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,bool got_write; retry: - open_flag = op->open_flag; + open_flag = open_flag_arg; got_write = false; - mode = op->mode; + mode = mode_arg; create_error =0 ;if (open_flag & (O_CREAT |O_TRUNC |O_WRONLY |O_RDWR )) { - got_write = !mnt_want_write (nd->path.mnt); + got_write = !mnt_want_write (path->mnt);/* * do _not_ fail yet - we might not need that or fail with * a different error; let lookup_open() decide; we'll be @@ -4440,17 +4443,17 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, } file->f_mode &= ~FMODE_CREATED ; - dentry =d_lookup (dir, &nd->last); + dentry =d_lookup (dir, last);for (;;) {if (!dentry) { - dentry =d_alloc_parallel (dir, &nd->last); + dentry =d_alloc_parallel (dir, last);if (IS_ERR (dentry)) goto out; }if (d_in_lookup (dentry))break ; - error =d_revalidate (dir_inode, &nd->last, dentry, nd->flags); + error =d_revalidate (dir_inode, last, dentry, lookup_flags);if (likely (error >0 ))break ;if (error)@@ -4465,7 +4468,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, }if (open_flag &O_CREAT ) -audit_inode (nd->name, dir,AUDIT_INODE_PARENT ); +audit_inode (name, dir,AUDIT_INODE_PARENT );/* * Checking write permission is tricky, bacuse we don't know if we are @@ -4478,13 +4481,13 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,*/ if (unlikely (!got_write)) open_flag &= ~O_TRUNC ; - idmap =mnt_idmap (nd->path.mnt); + idmap =mnt_idmap (path->mnt);if (open_flag &O_CREAT ) {if (open_flag &O_EXCL ) open_flag &= ~O_TRUNC ; mode =vfs_prepare_mode (idmap, dir_inode, mode, mode, mode);if (likely (got_write)) - create_error =may_o_create (idmap, &nd->path, + create_error =may_o_create (idmap, path, dentry, mode);else create_error = -EROFS ;@@ -4492,9 +4495,9 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,if (create_error) open_flag &= ~O_CREAT ;if (dir_inode->i_op->atomic_open) { -if (nd->flags &LOOKUP_DIRECTORY ) +if (lookup_flags &LOOKUP_DIRECTORY ) open_flag |=O_DIRECTORY ; - dentry =atomic_open (&nd->path, dentry, file, open_flag, mode); + dentry =atomic_open (path, dentry, file, open_flag, mode);if (unlikely (create_error) && dentry ==ERR_PTR (-ENOENT )) dentry =ERR_PTR (create_error); goto out;@@ -4502,7 +4505,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,if (d_in_lookup (dentry)) {struct dentry *res = dir_inode->i_op->lookup (dir_inode, dentry, - nd->flags); + lookup_flags);d_lookup_done (dentry);if (unlikely (res)) {if (IS_ERR (res)) {@@ -4550,7 +4553,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,inode_unlock_shared (dir_inode);if (got_write) -mnt_drop_write (nd->path.mnt); +mnt_drop_write (path->mnt);if (is_delegated (&delegated_inode)) {/* Must have come through out_dput */ @@ -4637,7 +4640,8 @@ static const char *open_last_lookups(struct nameidata *nd, } } - dentry =lookup_open (nd, file, op); + dentry =lookup_open (&nd->path, file, &nd->last, + nd->flags, nd->name, op->open_flag, op->mode);if (IS_ERR (dentry))return ERR_CAST (dentry);Signature · 1 line
2.50.0.107.gf914562f5916.dirty
Sure. I think the churn and pushing nd state through many arguments would normally be too much to justify the improvement of scope reduction, but for the goal of getting rid of dentry_create() this is fine.
PATCH 4/18 VFS: add vfs_lookup_open()
In reply to NeilBrownFrom: NeilBrown <[email protected]>
vfs_lookup_open() is a limited version of lookup_open() which is exported for nfsd to use - to replace dentry_create().
It is limited in that no filename is given (thus no auditing) and no LOOKUP_ flags are passed. A few "intent" LOOKUP flags are deduced from the open flags.
--- fs/namei.c | 54 +++++++++++++++++++++++++++++++++++++++++++ include/linux/namei.h | 3 +++ 2 files changed, 57 insertions(+)
fs/namei.c +54 -0
@@ -4571,6 +4571,60 @@ static struct dentry *lookup_open(const struct path *path, struct file *file, goto out; } +/** +* vfs_lookup_open - open and possibly create a regular file +* @parent: directory to contain file +* @last: final component of file name +* @open_flag: O_flags +* @mode: initial permissions for file +* +* Open a file after lookup and/or create. This provides similar +* functionality open_last_lookups() for in-kernel users, particularly +* nfsd. +* It uses ->atomic_open or ->lookup / ->create / ->open as appropriate. +* +* Returns: the opened struct file, or an error. +*/ +struct file *vfs_lookup_open (struct path *parent,struct qstr *last, +int open_flag,umode_t mode) +{ + struct file *file __free(fput) = NULL; +unsigned int lookup_flags =LOOKUP_OPEN ; +struct dentry *dentry; +int error =0 ; + + error =lookup_noperm_common (last, parent->dentry); +if (error) +return ERR_PTR (error); + + file =alloc_empty_file (open_flag,current_cred ()); +if (IS_ERR (file)) +return file; + +if (open_flag &O_CREAT ) { + lookup_flags |=LOOKUP_CREATE ; +if (open_flag &O_EXCL ) + lookup_flags |=LOOKUP_EXCL ; + } + dentry =lookup_open (parent, file, last, lookup_flags,NULL , + open_flag,S_IFREG | mode); +if (IS_ERR (dentry)) +return ERR_CAST (dentry); + +if (d_really_is_negative (dentry)) { + error = -ENOENT ; + }else if (!(file->f_mode &FMODE_OPENED )) { +struct path path = {.mnt = parent->mnt, .dentry = dentry }; + + error =vfs_open (&path, file); + } +dput (dentry); + +if (error) +return ERR_PTR (error); +return no_free_ptr (file); +} +static inline bool trailing_slashes (struct nameidata *nd) {return (bool )nd->last.name[nd->last.len];
include/linux/namei.h +3 -0
@@ -103,6 +103,9 @@ struct dentry *start_creating_dentry(struct dentry *parent,struct dentry *start_removing_dentry (struct dentry *parent,struct dentry *child); +struct file *vfs_lookup_open (struct path *parent,struct qstr *last, +int open_flag,umode_t mode); +/* end_creating - finish action started with start_creating * @child: dentry returned by start_creating() or vfs_mkdir() *
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
Re: [PATCH 04/18] VFS: add vfs_lookup_open()
Quoted 51 lines
Op 01-06-2026 08:37 CEST schreef NeilBrown <[email protected]>:
From: NeilBrown <[email protected]>
vfs_lookup_open()is a limited version oflookup_open()which is exported for nfsd to use - to replacedentry_create().It is limited in that no filename is given (thus no auditing) and no
LOOKUP_flags are passed. A few "intent" LOOKUP flags are deduced from the open flags.Signed-off-by NeilBrown <[email protected]>--- fs/namei.c | 54 +++++++++++++++++++++++++++++++++++++++++++ include/linux/namei.h | 3 +++ 2 files changed, 57 insertions(+)fs/namei.c +24
-0@@ -4571,6 +4571,60 @@ static struct dentry *lookup_open(const struct path *path, struct file *file, goto out; } +/** +* vfs_lookup_open - open and possibly create a regular file +* @parent: directory to contain file +* @last: final component of file name +* @open_flag: O_flags +* @mode: initial permissions for file +* +* Open a file after lookup and/or create. This provides similar +* functionality open_last_lookups() for in-kernel users, particularly +* nfsd. +* It uses ->atomic_open or ->lookup / ->create / ->open as appropriate. +* +* Returns: the opened struct file, or an error. +*/ +struct file *vfs_lookup_open (struct path *parent,struct qstr *last, +int open_flag,umode_t mode) +{ + struct file *file __free(fput) = NULL; +unsigned int lookup_flags =LOOKUP_OPEN ; +struct dentry *dentry; +int error =0 ; + + error =lookup_noperm_common (last, parent->dentry); +if (error)
fs/namei.c static struct dentry *lookup_open(const struct path *path, struct file *file, · line 4607
Quoted 10 lines
fs/namei.c +10
-0+return ERR_PTR (error); + + file =alloc_empty_file (open_flag,current_cred ()); +if (IS_ERR (file)) +return file; + +if (open_flag &O_CREAT ) { + lookup_flags |=LOOKUP_CREATE ; +if (open_flag &O_EXCL ) + lookup_flags |=LOOKUP_EXCL ;
Is O_EXCL enforced anywhere in this call path? I don't really know nfsd, but for the standard O_CREAT call chain, this happens in do_open(), and EEXIST is returned.
Also, maybe warn when nonsensical bits here, like __O_TMPFILE, are set in open_flag?
fs/namei.c static struct dentry *lookup_open(const struct path *path, struct file *file, · line 4619
Quoted 12 lines
fs/namei.c +12
-0+ } + dentry =lookup_open (parent, file, last, lookup_flags,NULL , + open_flag,S_IFREG | mode); +if (IS_ERR (dentry)) +return ERR_CAST (dentry); + +if (d_really_is_negative (dentry)) { + error = -ENOENT ; + }else if (!(file->f_mode &FMODE_OPENED )) { +struct path path = {.mnt = parent->mnt, .dentry = dentry }; + + error =vfs_open (&path, file);
Ah, good, this fixes the bug in dentry_create() where on failing the open part of atomic_open() no other attempt was done by the vfs to do the open.
Quoted 27 lines
fs/namei.c +8
-0+ } +dput (dentry); + +if (error) +return ERR_PTR (error); +return no_free_ptr (file); +} +static inline bool trailing_slashes (struct nameidata *nd) {return (bool )nd->last.name[nd->last.len];include/linux/namei.h +3
-0@@ -103,6 +103,9 @@ struct dentry *start_creating_dentry(struct dentry *parent,struct dentry *start_removing_dentry (struct dentry *parent,struct dentry *child); +struct file *vfs_lookup_open (struct path *parent,struct qstr *last, +int open_flag,umode_t mode); +/* end_creating - finish action started with start_creating * @child: dentry returned by start_creating() or vfs_mkdir() * Signature · 1 line
2.50.0.107.gf914562f5916.dirty
PATCH 5/18 VFS: dentry_create: always set FMODE_CREATE when file is created.
In reply to NeilBrownFrom: NeilBrown <[email protected]>
atomic_open() may or may not need to create the file, and sets FMODE_CREATE to indicate that it has. To allow the caller to know if the file was actually created, set FMODE_CREATE in the vfs_create() branch too.
--- fs/namei.c | 2 ++ 1 file changed, 2 insertions(+)
fs/namei.c +2 -0
@@ -5137,6 +5137,8 @@ struct file *dentry_create(struct path *path, int flags, umode_t mode, error =vfs_create (mnt_idmap (path->mnt), path->dentry, mode,NULL );if (!error) error =vfs_open (path, file); +if (!error) + file->f_mode |=FMODE_CREATED ; }if (unlikely (error))return ERR_PTR (error);
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
Re: [PATCH 05/18] VFS: dentry_create: always set FMODE_CREATE when file is created.
Quoted 21 lines
Op 01-06-2026 08:37 CEST schreef NeilBrown <[email protected]>:
From: NeilBrown <[email protected]>
atomic_open()may or may not need to create the file, and setsFMODE_CREATEto indicate that it has. To allow the caller to know if the file was actually created, setFMODE_CREATEin thevfs_create()branch too.Signed-off-by NeilBrown <[email protected]>--- fs/namei.c | 2 ++ 1 file changed, 2 insertions(+)fs/namei.c +0
-0
fs/namei.c struct file *dentry_create(struct path *path, int flags, umode_t mode, · line 5141
Quoted 5 lines
fs/namei.c +2
-0@@ -5137,6 +5137,8 @@ struct file *dentry_create(struct path *path, int flags, umode_t mode, error =vfs_create (mnt_idmap (path->mnt), path->dentry, mode,NULL );if (!error) error =vfs_open (path, file); +if (!error) + file->f_mode |=FMODE_CREATED ;
What if vfs_create() succeeded but vfs_open() failed? Then we don't set FMODE_CREATED, why?
Quoted 5 lines
fs/namei.c +0
-0}if (unlikely (error))return ERR_PTR (error);Signature · 1 line
2.50.0.107.gf914562f5916.dirty
PATCH 6/18 nfsd: replace fh_fill_both_attrs() with fh_fill_post_noop()
In reply to NeilBrownFrom: NeilBrown <[email protected]>
fh_fill_both_attrs() is only needed for open/create and is used in the case when the target already existed so no creating happens.
As part of refactoring this code it is changed to call fh_fill_pre_attrs() once early on (so errors only need to be caught in one place) and then to use a new fh_fill_post_noop() when it is determined that no creation happened.
fh_fill_pre_attrs() now stores the attrs (which it had to get all of anyway)_ in ->fh_post_attr. fh_fill_post_noop() simply marks them as valid. fh_fill_post_attrs() replaces them.
--- fs/nfsd/nfs4proc.c | 19 ++++++++----------- fs/nfsd/nfsfh.c | 40 +++++++++++----------------------------- fs/nfsd/nfsfh.h | 13 ++++++++++++- 3 files changed, 31 insertions(+), 41 deletions(-)
fs/nfsd/nfs4proc.c +8 -11
@@ -327,9 +327,7 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,/* NFSv4 protocol requires change attributes even though * no change happened. */ - status =fh_fill_both_attrs (fhp); -if (status != nfs_ok) - goto out; +fh_fill_post_noop (fhp); status =fh_compose (resfhp, fhp->fh_export, child, fhp);if (status != nfs_ok)
@@ -376,9 +374,6 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,if (!IS_POSIXACL (inode)) iap->ia_mode &= ~current_umask (); - status =fh_fill_pre_attrs (fhp); -if (status != nfs_ok) - goto out; status =nfsd4_vfs_create (fhp, &child, open);if (status != nfs_ok) goto out;
@@ -464,6 +459,9 @@ do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, strufh_init (*resfh,NFS4_FHSIZE ); open->op_truncate = false; + status =fh_fill_pre_attrs (current_fh); +if (status) + goto out;if (open->op_create) {/* FIXME: check session persistence and pnfs flags. * The nfsv4.1 spec requires the following semantics:
@@ -495,11 +493,10 @@ do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, stru }else { status =nfsd_lookup (rqstp, current_fh, open->op_fname, open->op_fnamelen, *resfh); -if (status == nfs_ok) -/* NFSv4 protocol requires change attributes even though -* no change happened. -*/ - status =fh_fill_both_attrs (current_fh); +/* NFSv4 protocol requires change attributes even though +* no change happened. +*/ +fh_fill_post_noop (current_fh); }if (status) goto out;
fs/nfsd/nfsfh.c +11 -29
@@ -782,26 +782,31 @@ __be32 fh_getattr(const struct svc_fh *fhp, struct kstat *stat)* fh_fill_pre_attrs - Fill in pre-op attributes * @fhp: file handle to be updated * +* Post-op attrs are filled and pre-op attrs are copied +* from there. The post-op attrs can later be replaced by +* fh_fill_post_attrs() or activated by fh_fill_post_noop(). +* +* Returns: error from vfs_getattr() which must be checked. */ __be32 __must_check fh_fill_pre_attrs (struct svc_fh *fhp) {bool v4 = (fhp->fh_maxsize ==NFS4_FHSIZE ); -struct kstat stat;__be32 err;if (fhp->fh_no_wcc || fhp->fh_pre_saved)return nfs_ok; - err =fh_getattr (fhp, &stat); + err =fh_getattr (fhp, &fhp->fh_post_attr);if (err)return err;if (v4) - fhp->fh_pre_change =nfsd4_change_attribute (&stat); + fhp->fh_pre_change = fhp->fh_post_change = +nfsd4_change_attribute (&fhp->fh_post_attr); - fhp->fh_pre_mtime = stat.mtime; - fhp->fh_pre_ctime = stat.ctime; - fhp->fh_pre_size = stat.size; + fhp->fh_pre_mtime = fhp->fh_post_attr.mtime; + fhp->fh_pre_ctime = fhp->fh_post_attr.ctime; + fhp->fh_pre_size = fhp->fh_post_attr.size; fhp->fh_pre_saved = true;return nfs_ok; }
@@ -833,29 +838,6 @@ __be32 fh_fill_post_attrs(struct svc_fh *fhp)return nfs_ok; } -/** -* fh_fill_both_attrs - Fill pre-op and post-op attributes -* @fhp: file handle to be updated -* -* This is used when the directory wasn't changed, but wcc attributes -* are needed anyway. -*/ -__be32 __must_check fh_fill_both_attrs (struct svc_fh *fhp) -{ -__be32 err; - - err =fh_fill_post_attrs (fhp); -if (err) -return err; - - fhp->fh_pre_change = fhp->fh_post_change; - fhp->fh_pre_mtime = fhp->fh_post_attr.mtime; - fhp->fh_pre_ctime = fhp->fh_post_attr.ctime; - fhp->fh_pre_size = fhp->fh_post_attr.size; - fhp->fh_pre_saved = true; -return nfs_ok; -} -/* * Release a file handle. */
fs/nfsd/nfsfh.h +12 -1
@@ -335,5 +335,16 @@ static inline void fh_clear_pre_post_attrs(struct svc_fh *fhp)u64 nfsd4_change_attribute (const struct kstat *stat);__be32 __must_check fh_fill_pre_attrs (struct svc_fh *fhp);__be32 fh_fill_post_attrs (struct svc_fh *fhp); -__be32 __must_check fh_fill_both_attrs (struct svc_fh *fhp); + +/** +* fh_fill_post_noop - Copy pre attrs to post attrs +* @fhp: file handle to be updated +* +* This is used when the directory wasn't changed, but wcc attributes +* are needed anyway. +*/ +static inline void fh_fill_post_noop (struct svc_fh *fhp) +{ + fhp->fh_post_saved = true; +}#endif /* _LINUX_NFSD_NFSFH_H */
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
PATCH 7/18 nfsd: move fh_want_write() after preamble in nfsd4_create_file()
In reply to NeilBrownFrom: NeilBrown <[email protected]>
As part of separating the nfsd-specific code from the VFS interaction code in nfsd4_create_file(), move fh_want_write() to just before we need it.
Also restructure the "if" statement in that preamble to only test is_create_with_attrs() once.
--- fs/nfsd/nfs4proc.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
fs/nfsd/nfs4proc.c +13 -13
@@ -270,22 +270,18 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, parent = fhp->fh_dentry; inode =d_inode (parent); - host_err =fh_want_write (fhp); -if (host_err) -return nfserrno (host_err); - -if (open->op_acl) { +if (!is_create_with_attrs (open)) { +/* No attrs to check */ + }else if (open->op_acl) {if (open->op_dpacl || open->op_pacl) { - status = nfserr_inval; - goto out; +/* Cannot specify both NFSv4 and Posix ACLs */ +return nfserr_inval; } -if (is_create_with_attrs (open)) { - status =nfsd4_acl_to_attr (NF4REG , open->op_acl, + status =nfsd4_acl_to_attr (NF4REG , open->op_acl, &attrs); -if (status) - goto out; - } - }else if (is_create_with_attrs (open)) { +if (status) + goto out; + }else {/* The dpacl and pacl will get released by nfsd_attrs_free(). */ attrs.na_dpacl = open->op_dpacl; attrs.na_pacl = open->op_pacl;
@@ -293,6 +289,10 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, open->op_pacl =NULL ; } + host_err =fh_want_write (fhp); +if (host_err) +return nfserrno (host_err); + child =start_creating (&nop_mnt_idmap, parent, &QSTR_LEN (open->op_fname, open->op_fnamelen));if (IS_ERR (child)) {
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
PATCH 8/18 nfsd: move more nfs-specific code into preamble of nfsd4_create_file()
In reply to NeilBrownFrom: NeilBrown <[email protected]>
Do NFS-specific prep before interacting with the VFS.
--- fs/nfsd/nfs4proc.c | 61 +++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 31 deletions(-)
fs/nfsd/nfs4proc.c +30 -31
@@ -270,6 +270,9 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, parent = fhp->fh_dentry; inode =d_inode (parent); +if (!IS_POSIXACL (inode)) + iap->ia_mode &= ~current_umask (); +if (!is_create_with_attrs (open)) {/* No attrs to check */ }else if (open->op_acl) {
@@ -289,22 +292,9 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, open->op_pacl =NULL ; } - host_err =fh_want_write (fhp); -if (host_err) -return nfserrno (host_err); - - child =start_creating (&nop_mnt_idmap, parent, - &QSTR_LEN (open->op_fname, open->op_fnamelen)); -if (IS_ERR (child)) { - status =nfserrno (PTR_ERR (child)); - goto out; - } - -if (d_really_is_negative (child)) { - status =fh_verify (rqstp, fhp,S_IFDIR ,NFSD_MAY_CREATE ); -if (status != nfs_ok) - goto out; - } +/* A newly created file already has a file size of zero. */ +if ((iap->ia_valid &ATTR_SIZE ) && (iap->ia_size ==0 )) + iap->ia_valid &= ~ATTR_SIZE ; v_mtime =0 ; v_atime =0 ;
@@ -321,6 +311,30 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,*/ v_mtime = verifier[0 ] &0x7fffffff ; v_atime = verifier[1 ] &0x7fffffff ; + + iap->ia_valid =ATTR_MTIME |ATTR_ATIME | +ATTR_MTIME_SET |ATTR_ATIME_SET ; + iap->ia_mtime.tv_sec = v_mtime; + iap->ia_atime.tv_sec = v_atime; + iap->ia_mtime.tv_nsec =0 ; + iap->ia_atime.tv_nsec =0 ; + } + + host_err =fh_want_write (fhp); +if (host_err) +return nfserrno (host_err); + + child =start_creating (&nop_mnt_idmap, parent, + &QSTR_LEN (open->op_fname, open->op_fnamelen)); +if (IS_ERR (child)) { + status =nfserrno (PTR_ERR (child)); + goto out; + } + +if (d_really_is_negative (child)) { + status =fh_verify (rqstp, fhp,S_IFDIR ,NFSD_MAY_CREATE ); +if (status != nfs_ok) + goto out; }if (d_really_is_positive (child)) {
@@ -371,9 +385,6 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, goto out; } -if (!IS_POSIXACL (inode)) - iap->ia_mode &= ~current_umask (); - status =nfsd4_vfs_create (fhp, &child, open);if (status != nfs_ok) goto out;
@@ -384,18 +395,6 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,if (status != nfs_ok) goto out; -/* A newly created file already has a file size of zero. */ -if ((iap->ia_valid &ATTR_SIZE ) && (iap->ia_size ==0 )) - iap->ia_valid &= ~ATTR_SIZE ; -if (nfsd4_create_is_exclusive (open->op_createmode)) { - iap->ia_valid =ATTR_MTIME |ATTR_ATIME | -ATTR_MTIME_SET |ATTR_ATIME_SET ; - iap->ia_mtime.tv_sec = v_mtime; - iap->ia_atime.tv_sec = v_atime; - iap->ia_mtime.tv_nsec =0 ; - iap->ia_atime.tv_nsec =0 ; - } - set_attr: status =nfsd_create_setattr (rqstp, fhp, resfhp, &attrs);
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
PATCH 9/18 nfsd: remove subtlety from nfsd4_create_file()
In reply to NeilBrownFrom: NeilBrown <[email protected]>
nfsd4_create_file() has a switch with cases for NFS4_CREATE_EXCLUSIVE and NFS4_CREATE_EXCLUSIVE4_1 which are identical except for one line which is marked "subtle" in both cases.
The difference boils down to a "goto". For the EXCLUSIVE case the target is "out:" which is after a setattr call. For EXCLUSIVE4_1 the target is "set_attr:" which is the start of that setattr call.
We already have a function is_create_with_attrs() which determines if the setattr is needed, and differentiates between these two cases. So if we guard the setattr with "is_create_with_attrs()", then we can "goto setattr" for both cases and so unify the two cases in the switch. This, I think, make the code clearer and less subtle.
--- fs/nfsd/nfs4proc.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-)
fs/nfsd/nfs4proc.c +14 -19
@@ -365,22 +365,15 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = nfserr_exist;break ;case NFS4_CREATE_EXCLUSIVE : -if (inode_get_mtime_sec (d_inode (child)) == v_mtime && -inode_get_atime_sec (d_inode (child)) == v_atime && -d_inode (child)->i_size ==0 ) { - open->op_created = true; -break ;/* subtle */ - } - status = nfserr_exist; -break ;case NFS4_CREATE_EXCLUSIVE4_1 :if (inode_get_mtime_sec (d_inode (child)) == v_mtime &&inode_get_atime_sec (d_inode (child)) == v_atime &&d_inode (child)->i_size ==0 ) { open->op_created = true; - goto set_attr;/* subtle */ + goto set_attr; } status = nfserr_exist; +break ; } goto out; }
@@ -396,16 +389,18 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, goto out; set_attr: - status =nfsd_create_setattr (rqstp, fhp, resfhp, &attrs); - -if (attrs.na_labelerr) - open->op_bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ; -if (attrs.na_paclerr || attrs.na_dpaclerr) - open->op_bmval[0 ] &= ~FATTR4_WORD0_ACL ; -if (attrs.na_dpaclerr) - open->op_bmval[2 ] &= ~FATTR4_WORD2_POSIX_DEFAULT_ACL ; -if (attrs.na_paclerr) - open->op_bmval[2 ] &= ~FATTR4_WORD2_POSIX_ACCESS_ACL ; +if (is_create_with_attrs (open)) { + status =nfsd_create_setattr (rqstp, fhp, resfhp, &attrs); + +if (attrs.na_labelerr) + open->op_bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ; +if (attrs.na_paclerr || attrs.na_dpaclerr) + open->op_bmval[0 ] &= ~FATTR4_WORD0_ACL ; +if (attrs.na_dpaclerr) + open->op_bmval[2 ] &= ~FATTR4_WORD2_POSIX_DEFAULT_ACL ; +if (attrs.na_paclerr) + open->op_bmval[2 ] &= ~FATTR4_WORD2_POSIX_ACCESS_ACL ; + } out:end_creating (child);nfsd_attrs_free (&attrs);
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
PATCH 10/18 nfsd: in nfsd4_create_file() let VFS report if file was created.
In reply to NeilBrownFrom: NeilBrown <[email protected]>
nfsd4_create_file() currently assumes that if a lookup failed but then a create succeeds, then the "create" created the file. With atomic_open this may not be the case - some other actor might have created the file between the lookup and the create.
So we move the call to nfsd4_vfs_create() earlier and set ->op_created based on that. Then use "! ->op_created" to trigger nfserr_exist handling.
The switch statement is split up into two if() statements. First we check for the possibility of a successful exclusive create and set ->op_create to true if appropriate. Then we check for NFS4_CREATE_UNCHECKED to decide if a pre-existing file means an error or success.
This allows us to combine the two fh_compose() calls to one place.
With this rearrangement we now repeat the setattr when an exclusive create is repeated. This should be both rare and harmless, and it simplifies the code.
--- fs/nfsd/nfs4proc.c | 75 ++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 42 deletions(-)
fs/nfsd/nfs4proc.c +33 -42
@@ -337,58 +337,49 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, goto out; } -if (d_really_is_positive (child)) { -/* NFSv4 protocol requires change attributes even though -* no change happened. -*/ -fh_fill_post_noop (fhp); - - status =fh_compose (resfhp, fhp->fh_export, child, fhp); +if (d_really_is_negative (child)) { + status =nfsd4_vfs_create (fhp, &child, open);if (status != nfs_ok) goto out; + open->op_created = open->op_filp->f_mode &FMODE_CREATED ; + } -switch (open->op_createmode) { -case NFS4_CREATE_UNCHECKED : -if (!d_is_reg (child)) -break ; + status =fh_compose (resfhp, fhp->fh_export, child, fhp); +if (status != nfs_ok) + goto out; -/* -* In NFSv4, we don't want to truncate the file -* now. This would be wrong if the OPEN fails for -* some other reason. Furthermore, if the size is -* nonzero, we should ignore it according to spec! -*/ - open->op_truncate = (iap->ia_valid &ATTR_SIZE ) && - !iap->ia_size; -break ; -case NFS4_CREATE_GUARDED : - status = nfserr_exist; -break ; -case NFS4_CREATE_EXCLUSIVE : -case NFS4_CREATE_EXCLUSIVE4_1 : -if (inode_get_mtime_sec (d_inode (child)) == v_mtime && -inode_get_atime_sec (d_inode (child)) == v_atime && -d_inode (child)->i_size ==0 ) { - open->op_created = true; - goto set_attr; - } - status = nfserr_exist; -break ; - } +if (!open->op_created && +nfsd4_create_is_exclusive (open->op_createmode) && +inode_get_mtime_sec (d_inode (child)) == v_mtime && +inode_get_atime_sec (d_inode (child)) == v_atime && +d_inode (child)->i_size ==0 ) + open->op_created = true; + +if (!open->op_created && + open->op_createmode ==NFS4_CREATE_UNCHECKED ) { +/* NFSv4 protocol requires change attributes +* even though no change happened. +*/ +fh_fill_post_noop (fhp); + +/* +* In NFSv4, we don't want to truncate the file +* now. This would be wrong if the OPEN fails for +* some other reason. Furthermore, if the size is +* nonzero, we should ignore it according to spec! +*/ + open->op_truncate = (d_is_reg (child) && + (iap->ia_valid &ATTR_SIZE ) && + !iap->ia_size); goto out; } - status =nfsd4_vfs_create (fhp, &child, open); -if (status != nfs_ok) +if (!open->op_created) { + status = nfserr_exist; goto out; - open->op_created = true; + }fh_fill_post_attrs (fhp); - status =fh_compose (resfhp, fhp->fh_export, child, fhp); -if (status != nfs_ok) - goto out; - -set_attr:if (is_create_with_attrs (open)) { status =nfsd_create_setattr (rqstp, fhp, resfhp, &attrs);
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
PATCH 11/18 nfsd: nfsd4_create_file(): remove NFSD_MAY_CREATE check.
In reply to NeilBrownFrom: NeilBrown <[email protected]>
This check is redundant as dentry_create() called by nfsd4_vfs_create() performs the same check.
--- fs/nfsd/nfs4proc.c | 6 ------ 1 file changed, 6 deletions(-)
fs/nfsd/nfs4proc.c +0 -6
@@ -331,12 +331,6 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, goto out; } -if (d_really_is_negative (child)) { - status =fh_verify (rqstp, fhp,S_IFDIR ,NFSD_MAY_CREATE ); -if (status != nfs_ok) - goto out; - } -if (d_really_is_negative (child)) { status =nfsd4_vfs_create (fhp, &child, open);if (status != nfs_ok)
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
PATCH 12/18 nfsd: reduce range of directory lock in nfsd4_create_file()
In reply to NeilBrownFrom: NeilBrown <[email protected]>
We only need to hold the lock taken by start_creating() until the create has been attempted. Holding for longer can serve no purpose.
The lock is currently held across the setattr call. This might be the intent but it serves no purpose. Holding the lock prevents the name from being removed or renamed, but it doesn't prevent a GETATTR or a racing SETATTR or an OPEN.
--- fs/nfsd/nfs4proc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/nfsd/nfs4proc.c +3 -3
@@ -333,10 +333,11 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,if (d_really_is_negative (child)) { status =nfsd4_vfs_create (fhp, &child, open); -if (status != nfs_ok) - goto out; open->op_created = open->op_filp->f_mode &FMODE_CREATED ; } +end_creating (child); +if (status != nfs_ok) + goto out; status =fh_compose (resfhp, fhp->fh_export, child, fhp);if (status != nfs_ok)
@@ -387,7 +388,6 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, open->op_bmval[2 ] &= ~FATTR4_WORD2_POSIX_ACCESS_ACL ; } out: -end_creating (child);nfsd_attrs_free (&attrs);fh_drop_write (fhp);return status;
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
PATCH 13/18 nfsd: open-code nfsd4_vfs_create() into nfsd4_create_file()
In reply to NeilBrownFrom: NeilBrown <[email protected]>
Having this sub function separate doesn't really add clarity, and merging allows for some refactoring and ultimately using a different VFS interface.
--- fs/nfsd/nfs4proc.c | 70 +++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 38 deletions(-)
fs/nfsd/nfs4proc.c +32 -38
@@ -201,41 +201,6 @@ static inline bool nfsd4_create_is_exclusive(int createmode) createmode ==NFS4_CREATE_EXCLUSIVE4_1 ; } -static __be32 -nfsd4_vfs_create (struct svc_fh *fhp,struct dentry **child, -struct nfsd4_open *open) -{ -struct file *filp; -struct path path; -int oflags; - - oflags =O_CREAT |O_LARGEFILE ; -if (nfsd4_create_is_exclusive (open->op_createmode)) - oflags |=O_EXCL ; - -switch (open->op_share_access &NFS4_SHARE_ACCESS_BOTH ) { -case NFS4_SHARE_ACCESS_WRITE : - oflags |=O_WRONLY ; -break ; -case NFS4_SHARE_ACCESS_BOTH : - oflags |=O_RDWR ; -break ; -default : - oflags |=O_RDONLY ; - } - - path.mnt = fhp->fh_export->ex_path.mnt; - path.dentry = *child; - filp =dentry_create (&path, oflags, open->op_iattr.ia_mode, -current_cred ()); - *child = path.dentry; - -if (IS_ERR (filp)) -return nfserrno (PTR_ERR (filp)); - - open->op_filp = filp; -return nfs_ok; -}/* * Implement NFSv4's unchecked, guarded, and exclusive create
@@ -332,12 +297,41 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, }if (d_really_is_negative (child)) { - status =nfsd4_vfs_create (fhp, &child, open); +struct file *filp; +struct path path; +int oflags; + + oflags =O_CREAT |O_LARGEFILE ; +if (nfsd4_create_is_exclusive (open->op_createmode)) + oflags |=O_EXCL ; + +switch (open->op_share_access &NFS4_SHARE_ACCESS_BOTH ) { +case NFS4_SHARE_ACCESS_WRITE : + oflags |=O_WRONLY ; +break ; +case NFS4_SHARE_ACCESS_BOTH : + oflags |=O_RDWR ; +break ; +default : + oflags |=O_RDONLY ; + } + + path.mnt = fhp->fh_export->ex_path.mnt; + path.dentry = child; + filp =dentry_create (&path, oflags, open->op_iattr.ia_mode, +current_cred ()); + child = path.dentry; + +if (IS_ERR (filp)) { +end_creating (child); + status =nfserrno (PTR_ERR (filp)); + goto out; + } + + open->op_filp = filp; open->op_created = open->op_filp->f_mode &FMODE_CREATED ; }end_creating (child); -if (status != nfs_ok) - goto out; status =fh_compose (resfhp, fhp->fh_export, child, fhp);if (status != nfs_ok)
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
PATCH 14/18 nfsd: move some code out of the d_really_is_negative() branch in nfsd4_create_file()
In reply to NeilBrownFrom: NeilBrown <[email protected]>
The benefit of this code movement isn't immediately obvious, but it will make it easier to switch to using lookup_open().
--- fs/nfsd/nfs4proc.c | 49 ++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 26 deletions(-)
fs/nfsd/nfs4proc.c +23 -26
@@ -218,7 +218,11 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, .na_iattr = iap, .na_seclabel = &open->op_label, }; +int oflags =O_CREAT |O_LARGEFILE ;struct dentry *parent, *child =ERR_PTR (-EINVAL ); +struct path path = { + .mnt = fhp->fh_export->ex_path.mnt, + };__u32 v_mtime, v_atime;struct inode *inode;__be32 status;
@@ -283,6 +287,19 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, iap->ia_atime.tv_sec = v_atime; iap->ia_mtime.tv_nsec =0 ; iap->ia_atime.tv_nsec =0 ; + + oflags |=O_EXCL ; + } + +switch (open->op_share_access &NFS4_SHARE_ACCESS_BOTH ) { +case NFS4_SHARE_ACCESS_WRITE : + oflags |=O_WRONLY ; +break ; +case NFS4_SHARE_ACCESS_BOTH : + oflags |=O_RDWR ; +break ; +default : + oflags |=O_RDONLY ; } host_err =fh_want_write (fhp);
@@ -295,40 +312,20 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status =nfserrno (PTR_ERR (child)); goto out; } + path.dentry = child;if (d_really_is_negative (child)) { -struct file *filp; -struct path path; -int oflags; - - oflags =O_CREAT |O_LARGEFILE ; -if (nfsd4_create_is_exclusive (open->op_createmode)) - oflags |=O_EXCL ; - -switch (open->op_share_access &NFS4_SHARE_ACCESS_BOTH ) { -case NFS4_SHARE_ACCESS_WRITE : - oflags |=O_WRONLY ; -break ; -case NFS4_SHARE_ACCESS_BOTH : - oflags |=O_RDWR ; -break ; -default : - oflags |=O_RDONLY ; - } - - path.mnt = fhp->fh_export->ex_path.mnt; - path.dentry = child; - filp =dentry_create (&path, oflags, open->op_iattr.ia_mode, -current_cred ()); + open->op_filp =dentry_create (&path, oflags, open->op_iattr.ia_mode, +current_cred ()); child = path.dentry; -if (IS_ERR (filp)) { +if (IS_ERR (open->op_filp)) {end_creating (child); - status =nfserrno (PTR_ERR (filp)); + status =nfserrno (PTR_ERR (open->op_filp)); + open->op_filp =NULL ; goto out; } - open->op_filp = filp; open->op_created = open->op_filp->f_mode &FMODE_CREATED ; }end_creating (child);
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
PATCH 15/18 nfsd: reduce want-write range in nfsd4_create_file(
In reply to NeilBrownFrom: NeilBrown <[email protected]>
nfsd4_create_file() needs write access to the mount for two purposes:
1/ to create/open the file.
2/ to set attributes on the newly created file.
Normally a file being created would be open for write, and once we have an active open we have the write access needed for a setattr. However if a file were created but opened read-only then the setattr wouldn't necessarily have write access to the mount.
Currently this is all handled by holding the write access across the open and the setattr. A subsequent patch will necessarily change how write access is gained for the open. So we reduce the range for the first want_write, and add another one only if setattr is needed on a read-only open.
--- fs/nfsd/nfs4proc.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
fs/nfsd/nfs4proc.c +23 -4
@@ -310,7 +310,7 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, &QSTR_LEN(open->op_fname, open->op_fnamelen));if (IS_ERR (child)) { status =nfserrno (PTR_ERR (child)); - goto out; + goto out_write; } path.dentry = child;
@@ -323,12 +323,13 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,end_creating (child); status =nfserrno (PTR_ERR (open->op_filp)); open->op_filp =NULL ; - goto out; + goto out_write; } open->op_created = open->op_filp->f_mode &FMODE_CREATED ; }end_creating (child); +fh_drop_write (fhp); status =fh_compose (resfhp, fhp->fh_export, child, fhp);if (status != nfs_ok)
@@ -367,7 +368,22 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,fh_fill_post_attrs (fhp);if (is_create_with_attrs (open)) { - status =nfsd_create_setattr (rqstp, fhp, resfhp, &attrs); +if (((oflags &O_ACCMODE ) ==O_RDONLY )) { +/* We will need write access to set the attrs, +* but a successful open won't provide that. +*/ +int host_err =fh_want_write (fhp); +if (host_err) { + status =nfserrno (host_err); + }else { + status =nfsd_create_setattr (rqstp, fhp, + resfhp, &attrs); +fh_drop_write (fhp); + } + }else { + status =nfsd_create_setattr (rqstp, fhp, + resfhp, &attrs); + }if (attrs.na_labelerr) open->op_bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ;
@@ -380,8 +396,11 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, } out:nfsd_attrs_free (&attrs); -fh_drop_write (fhp);return status; + +out_write: +fh_drop_write (fhp); + goto out; }/**
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
PATCH 16/18 nfsd: switch nfsd4_create_file() to use vfs_lookup_open()
In reply to NeilBrownFrom: NeilBrown <[email protected]>
Currently nfsd4_create_file() performs a lookup via start_creating() and then if that reports a negative dentry it uses dentry_create() to create the file.dentry_create() will use ->atomic_open if available. Part of the point of supporting atomic_open is to avoid needing a separate lookup. ->atomic_open can do lookup, create, open all in one operation. So doing a lookup before dentry_create() is not optimal.
So change to use vfs_lookup_open() which combines lookup, create, and open, either by using atomic_open or by calling the individual functions (but not both).
This means that we don't need to lock that parent (start_creating/end_creating).
We also don't need to get write-access (fh_want_write/fh_drop_write) except in the unusual case of a read-only creating open.
Also we only set O_EXCL in the NFS4_CREATE_GUARDED case. This the an NFS protocol option which requests the server to take full responsibility for atomic-create. For NFS4_CREATE_EXCLUSIVE and NFS4_CREATE_EXCLUSIVE4_1 the NFS protocol takes responsibilty for exclusive create by providing a verifier to store with the file, and using O_EXCL would interfere with this.
--- fs/nfsd/nfs4proc.c | 59 ++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 39 deletions(-)
fs/nfsd/nfs4proc.c +20 -39
@@ -219,14 +219,13 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, .na_seclabel = &open->op_label, };int oflags =O_CREAT |O_LARGEFILE ; -struct dentry *parent, *child =ERR_PTR (-EINVAL ); -struct path path = { +struct dentry *child =ERR_PTR (-EINVAL ); +struct path parent = { .mnt = fhp->fh_export->ex_path.mnt, + .dentry = fhp->fh_dentry, };__u32 v_mtime, v_atime; -struct inode *inode;__be32 status; -int host_err;if (isdotent (open->op_fname, open->op_fnamelen))return nfserr_exist;
@@ -236,10 +235,8 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status =fh_verify (rqstp, fhp,S_IFDIR ,NFSD_MAY_EXEC );if (status != nfs_ok)return status; - parent = fhp->fh_dentry; - inode =d_inode (parent); -if (!IS_POSIXACL (inode)) +if (!IS_POSIXACL (d_inode (parent.dentry))) iap->ia_mode &= ~current_umask ();if (!is_create_with_attrs (open)) {
@@ -287,9 +284,12 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, iap->ia_atime.tv_sec = v_atime; iap->ia_mtime.tv_nsec =0 ; iap->ia_atime.tv_nsec =0 ; - - oflags |=O_EXCL ; } +/* Only ask the fs to provide exclusive-create if we aren't using +* the NFS verifier to do it outselves. +*/ +if (open->op_createmode ==NFS4_CREATE_GUARDED ) + oflags |=O_EXCL ;switch (open->op_share_access &NFS4_SHARE_ACCESS_BOTH ) {case NFS4_SHARE_ACCESS_WRITE :
@@ -302,33 +302,18 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, oflags |=O_RDONLY ; } - host_err =fh_want_write (fhp); -if (host_err) -return nfserrno (host_err); - - child =start_creating (&nop_mnt_idmap, parent, - &QSTR_LEN (open->op_fname, open->op_fnamelen)); -if (IS_ERR (child)) { - status =nfserrno (PTR_ERR (child)); - goto out_write; - } - path.dentry = child; - -if (d_really_is_negative (child)) { - open->op_filp =dentry_create (&path, oflags, open->op_iattr.ia_mode, -current_cred ()); - child = path.dentry; - -if (IS_ERR (open->op_filp)) { -end_creating (child); - status =nfserrno (PTR_ERR (open->op_filp)); - open->op_filp =NULL ; - goto out_write; - } - - open->op_created = open->op_filp->f_mode &FMODE_CREATED ; + open->op_filp =vfs_lookup_open (&parent, + &QSTR_LEN (open->op_fname, + open->op_fnamelen), + oflags, + open->op_iattr.ia_mode); +if (IS_ERR (open->op_filp)) { + status =nfserrno (PTR_ERR (open->op_filp)); + open->op_filp =NULL ; + goto out; } -end_creating (child); + child = open->op_filp->f_path.dentry; + open->op_created = open->op_filp->f_mode &FMODE_CREATED ;fh_drop_write (fhp); status =fh_compose (resfhp, fhp->fh_export, child, fhp);
@@ -397,10 +382,6 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, out:nfsd_attrs_free (&attrs);return status; - -out_write: -fh_drop_write (fhp); - goto out; }/**
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
Chuck Lever
maintainerRe: [PATCH 16/18] nfsd: switch nfsd4_create_file() to use vfs_lookup_open()
fs/nfsd/nfs4proc.c nfsd4_create_file(struct svc_rqst *rqstp, struct · line 306
Quoted 11 lines · NeilBrown
fs/nfsd/nfs4proc.c +0
-1@@ -302,33 +302,18 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, oflags |=O_RDONLY ; } - host_err =fh_want_write (fhp);
This fh_want_write() is removed, but ...
Quoted 28 lines
fs/nfsd/nfs4proc.c +4
-24-if (host_err) -return nfserrno (host_err); - - child =start_creating (&nop_mnt_idmap, parent, - &QSTR_LEN (open->op_fname, open->op_fnamelen)); -if (IS_ERR (child)) { - status =nfserrno (PTR_ERR (child)); - goto out_write; - } - path.dentry = child; - -if (d_really_is_negative (child)) { - open->op_filp =dentry_create (&path, oflags, open->op_iattr.ia_mode, -current_cred ()); - child = path.dentry; - -if (IS_ERR (open->op_filp)) { -end_creating (child); - status =nfserrno (PTR_ERR (open->op_filp)); - open->op_filp =NULL ; - goto out_write; - } - - open->op_created = open->op_filp->f_mode &FMODE_CREATED ; + open->op_filp = vfs_lookup_open(&parent, + &QSTR_LEN(open->op_fname, + open->op_fnamelen), + oflags,
fs/nfsd/nfs4proc.c nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 317
Quoted 10 lines
fs/nfsd/nfs4proc.c +7
-1+ open->op_iattr.ia_mode); +if (IS_ERR (open->op_filp)) { + status =nfserrno (PTR_ERR (open->op_filp)); + open->op_filp =NULL ; + goto out; } -end_creating (child); + child = open->op_filp->f_path.dentry; + open->op_created = open->op_filp->f_mode &FMODE_CREATED ;fh_drop_write (fhp);
... the "matching" fh_drop_write remains. Harmless since nothing
has set fhp->fh_want_write, but should be cleaned up.
Quoted 2 lines
fs/nfsd/nfs4proc.c +0
-0status =fh_compose (resfhp, fhp->fh_export, child, fhp);
Signature · 1 line
Chuck Lever
Re: [PATCH 16/18] nfsd: switch nfsd4_create_file() to use vfs_lookup_open()
Quoted 50 lines · Chuck Lever
fs/nfsd/nfs4proc.c nfsd4_create_file(struct svc_rqst *rqstp, struct · line 306
Quoted 11 lines · NeilBrown
fs/nfsd/nfs4proc.c +0
-1@@ -302,33 +302,18 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, oflags |=O_RDONLY ; } - host_err =fh_want_write (fhp);This
fh_want_write()is removed, but ...Quoted 33 lines
fs/nfsd/nfs4proc.c +9
-24-if (host_err) -return nfserrno (host_err); - - child =start_creating (&nop_mnt_idmap, parent, - &QSTR_LEN (open->op_fname, open->op_fnamelen)); -if (IS_ERR (child)) { - status =nfserrno (PTR_ERR (child)); - goto out_write; - } - path.dentry = child; - -if (d_really_is_negative (child)) { - open->op_filp =dentry_create (&path, oflags, open->op_iattr.ia_mode, -current_cred ()); - child = path.dentry; - -if (IS_ERR (open->op_filp)) { -end_creating (child); - status =nfserrno (PTR_ERR (open->op_filp)); - open->op_filp =NULL ; - goto out_write; - } - - open->op_created = open->op_filp->f_mode &FMODE_CREATED ; + open->op_filp =vfs_lookup_open (&parent, + &QSTR_LEN (open->op_fname, + open->op_fnamelen), + oflags, + open->op_iattr.ia_mode); +if (IS_ERR (open->op_filp)) { + status =nfserrno (PTR_ERR (open->op_filp)); + open->op_filp =NULL ; + goto out;
Quoted 8 lines
fs/nfsd/nfs4proc.c nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, · line 317
Quoted 5 lines
fs/nfsd/nfs4proc.c +2
-1} -end_creating (child); + child = open->op_filp->f_path.dentry; + open->op_created = open->op_filp->f_mode &FMODE_CREATED ;fh_drop_write (fhp);... the "matching"
fh_drop_writeremains. Harmless since nothing
has setfhp->fh_want_write, but should be cleaned up.
Thanks for catching that!
NeilBrown
Quoted 9 lines
Quoted 4 lines
fs/nfsd/nfs4proc.c +0
-0status =fh_compose (resfhp, fhp->fh_export, child, fhp);Signature · 1 line
Chuck Lever
PATCH 17/18 nfsd: use vfs_lookup_open() for non-creating open requests too.
In reply to NeilBrownFrom: NeilBrown <[email protected]>
Now that we use vfs_lookup_open() for creating open requests, we can use for non-creating too as vfs_lookup_open() is already able to do that.
This means that when exporting NFS, the lookup and open can be combined using ->atomic_open.
The resulting simplification allows fh_fill_pre_attrs() to be moved into nfsd4_open_file() (renamed from nfsd4_create_file()) so it is closer to fh_full_post_attrs and fh_fill_post_noop calls.
As ->op_create_mode isn't defined when op_create is zero, we need a local create_mode which is -1 (illegal value) when op_create is zero.
--- fs/nfsd/nfs4proc.c | 97 +++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 49 deletions(-)
fs/nfsd/nfs4proc.c +48 -49
@@ -201,30 +201,30 @@ static inline bool nfsd4_create_is_exclusive(int createmode) createmode ==NFS4_CREATE_EXCLUSIVE4_1 ; } -/* -* Implement NFSv4's unchecked, guarded, and exclusive create -* semantics for regular files. Open state for this new file is -* subsequently fabricated in nfsd4_process_open2(). -* +* Implement NFSv4's open semantics for regular files. +* Both create (unchecked, guarded, and exclusive) and non-create. +* Open state for this new file is subsequently fabricated in +* nfsd4_process_open2(). * Upon return, caller must release @fhp and @resfhp. */ static __be32 -nfsd4_create_file (struct svc_rqst *rqstp,struct svc_fh *fhp, -struct svc_fh *resfhp,struct nfsd4_open *open) +nfsd4_open_file (struct svc_rqst *rqstp,struct svc_fh *fhp, +struct svc_fh *resfhp,struct nfsd4_open *open) {struct iattr *iap = &open->op_iattr;struct nfsd_attrs attrs = { .na_iattr = iap, .na_seclabel = &open->op_label, }; -int oflags =O_CREAT |O_LARGEFILE ; +int oflags =O_LARGEFILE ;struct dentry *child =ERR_PTR (-EINVAL );struct path parent = { .mnt = fhp->fh_export->ex_path.mnt, .dentry = fhp->fh_dentry, };__u32 v_mtime, v_atime; +int createmode =-1 ;__be32 status;if (isdotent (open->op_fname, open->op_fnamelen))
@@ -236,6 +236,10 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,if (status != nfs_ok)return status; + status =fh_fill_pre_attrs (fhp); +if (status) +return status; +if (!IS_POSIXACL (d_inode (parent.dentry))) iap->ia_mode &= ~current_umask ();
@@ -258,13 +262,18 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, open->op_pacl =NULL ; } +if (open->op_create) { + createmode = open->op_createmode; + oflags |=O_CREAT ; + } +/* A newly created file already has a file size of zero. */ if ((iap->ia_valid &ATTR_SIZE ) && (iap->ia_size ==0 )) iap->ia_valid &= ~ATTR_SIZE ; v_mtime =0 ; v_atime =0 ; -if (nfsd4_create_is_exclusive (open->op_createmode)) { +if (nfsd4_create_is_exclusive (createmode)) {u32 *verifier = (u32 *)open->op_verf.data;/*
@@ -288,7 +297,7 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,/* Only ask the fs to provide exclusive-create if we aren't using * the NFS verifier to do it outselves. */ -if (open->op_createmode ==NFS4_CREATE_GUARDED ) +if (createmode ==NFS4_CREATE_GUARDED ) oflags |=O_EXCL ;switch (open->op_share_access &NFS4_SHARE_ACCESS_BOTH ) {
@@ -321,14 +330,14 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, goto out;if (!open->op_created && -nfsd4_create_is_exclusive (open->op_createmode) && +nfsd4_create_is_exclusive (createmode) &&inode_get_mtime_sec (d_inode (child)) == v_mtime &&inode_get_atime_sec (d_inode (child)) == v_atime &&d_inode (child)->i_size ==0 ) open->op_created = true;if (!open->op_created && - open->op_createmode ==NFS4_CREATE_UNCHECKED ) { + createmode ==NFS4_CREATE_UNCHECKED ) {/* NFSv4 protocol requires change attributes * even though no change happened. */
@@ -429,45 +438,35 @@ do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, strufh_init (*resfh,NFS4_FHSIZE ); open->op_truncate = false; - status =fh_fill_pre_attrs (current_fh); -if (status) - goto out; -if (open->op_create) { -/* FIXME: check session persistence and pnfs flags. -* The nfsv4.1 spec requires the following semantics: -* -* Persistent | pNFS | Server REQUIRED | Client Allowed -* Reply Cache | server | | -* -------------+--------+-----------------+-------------------- -* no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 -* | | | (SHOULD) -* | | and EXCLUSIVE4 | or EXCLUSIVE4 -* | | | (SHOULD NOT) -* no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 -* yes | no | GUARDED4 | GUARDED4 -* yes | yes | GUARDED4 | GUARDED4 -*/ +/* FIXME: check session persistence and pnfs flags. +* The nfsv4.1 spec requires the following semantics: +* +* Persistent | pNFS | Server REQUIRED | Client Allowed +* Reply Cache | server | | +* -------------+--------+-----------------+-------------------- +* no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 +* | | | (SHOULD) +* | | and EXCLUSIVE4 | or EXCLUSIVE4 +* | | | (SHOULD NOT) +* no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 +* yes | no | GUARDED4 | GUARDED4 +* yes | yes | GUARDED4 | GUARDED4 +*/ - current->fs->umask = open->op_umask; - status =nfsd4_create_file (rqstp, current_fh, *resfh, open); - current->fs->umask =0 ; + current->fs->umask = open->op_umask; + status =nfsd4_open_file (rqstp, current_fh, *resfh, open); + current->fs->umask =0 ; + +/* +* Following rfc 3530 14.2.16, and rfc 5661 18.16.4 +* use the returned bitmask to indicate which attributes +* we used to store the verifier: +*/ +if (open->op_create && status ==0 && +nfsd4_create_is_exclusive (open->op_createmode)) + open->op_bmval[1 ] |= (FATTR4_WORD1_TIME_ACCESS | +FATTR4_WORD1_TIME_MODIFY ); -/* -* Following rfc 3530 14.2.16, and rfc 5661 18.16.4 -* use the returned bitmask to indicate which attributes -* we used to store the verifier: -*/ -if (nfsd4_create_is_exclusive (open->op_createmode) && status ==0 ) - open->op_bmval[1 ] |= (FATTR4_WORD1_TIME_ACCESS | -FATTR4_WORD1_TIME_MODIFY ); - }else { - status =nfsd_lookup (rqstp, current_fh, - open->op_fname, open->op_fnamelen, *resfh); -/* NFSv4 protocol requires change attributes even though -* no change happened. -*/ -fh_fill_post_noop (current_fh); - }if (status) goto out; status =nfsd_check_obj_isreg (*resfh, cstate->minorversion);
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
Chuck Lever
maintainerRe: [PATCH 17/18] nfsd: use vfs_lookup_open() for non-creating open requests too.
Quoted 64 lines · NeilBrown
(quoted diff) +0
-0@@ -429,45 +438,35 @@ do_open_lookup(struct svc_rqst *rqstp, struct
nfsd4_compound_state*cstate, strufs/nfsd/nfs4proc.c +27
-30fh_init (*resfh,NFS4_FHSIZE ); open->op_truncate = false; - status =fh_fill_pre_attrs (current_fh); -if (status) - goto out; -if (open->op_create) { -/* FIXME: check session persistence and pnfs flags. -* The nfsv4.1 spec requires the following semantics: -* -* Persistent | pNFS | Server REQUIRED | Client Allowed -* Reply Cache | server | | -* -------------+--------+-----------------+-------------------- -* no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 -* | | | (SHOULD) -* | | and EXCLUSIVE4 | or EXCLUSIVE4 -* | | | (SHOULD NOT) -* no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 -* yes | no | GUARDED4 | GUARDED4 -* yes | yes | GUARDED4 | GUARDED4 -*/ +/* FIXME: check session persistence and pnfs flags. +* The nfsv4.1 spec requires the following semantics: +* +* Persistent | pNFS | Server REQUIRED | Client Allowed +* Reply Cache | server | | +* -------------+--------+-----------------+-------------------- +* no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 +* | | | (SHOULD) +* | | and EXCLUSIVE4 | or EXCLUSIVE4 +* | | | (SHOULD NOT) +* no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 +* yes | no | GUARDED4 | GUARDED4 +* yes | yes | GUARDED4 | GUARDED4 +*/ - current->fs->umask = open->op_umask; - status =nfsd4_create_file (rqstp, current_fh, *resfh, open); - current->fs->umask =0 ; + current->fs->umask = open->op_umask; + status =nfsd4_open_file (rqstp, current_fh, *resfh, open); + current->fs->umask =0 ; + +/* +* Following rfc 3530 14.2.16, and rfc 5661 18.16.4 +* use the returned bitmask to indicate which attributes +* we used to store the verifier: +*/ +if (open->op_create && status ==0 && +nfsd4_create_is_exclusive (open->op_createmode)) + open->op_bmval[1 ] |= (FATTR4_WORD1_TIME_ACCESS | +FATTR4_WORD1_TIME_MODIFY ); -/* -* Following rfc 3530 14.2.16, and rfc 5661 18.16.4 -* use the returned bitmask to indicate which attributes -* we used to store the verifier: -*/ -if (nfsd4_create_is_exclusive (open->op_createmode) && status ==0 ) - open->op_bmval[1 ] |= (FATTR4_WORD1_TIME_ACCESS | -FATTR4_WORD1_TIME_MODIFY ); - }else {
fs/nfsd/nfs4proc.c do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, stru · line 472
Quoted 10 lines
fs/nfsd/nfs4proc.c +0
-7- status =nfsd_lookup (rqstp, current_fh, - open->op_fname, open->op_fnamelen, *resfh); -/* NFSv4 protocol requires change attributes even though -* no change happened. -*/ -fh_fill_post_noop (current_fh); - }if (status) goto out; status =nfsd_check_obj_isreg (*resfh, cstate->minorversion);
Logic bug: Pre-series, the non-create case takes do_open_lookup()'s else branch and succeeds; post-series, do_open_lookup() calls nfsd4_open_file() unconditionally. Every CLAIM_NULL open of an existing file fails with NFS4ERR_EXIST.
Signature · 1 line
Chuck Lever
Re: [PATCH 17/18] nfsd: use vfs_lookup_open() for non-creating open requests too.
Quoted 74 lines · Chuck Lever
Quoted 71 lines · NeilBrown
(quoted diff) +0
-0@@ -429,45 +438,35 @@ do_open_lookup(struct svc_rqst *rqstp, struct
nfsd4_compound_state*cstate, strufs/nfsd/nfs4proc.c +27
-37fh_init (*resfh,NFS4_FHSIZE ); open->op_truncate = false; - status =fh_fill_pre_attrs (current_fh); -if (status) - goto out; -if (open->op_create) { -/* FIXME: check session persistence and pnfs flags. -* The nfsv4.1 spec requires the following semantics: -* -* Persistent | pNFS | Server REQUIRED | Client Allowed -* Reply Cache | server | | -* -------------+--------+-----------------+-------------------- -* no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 -* | | | (SHOULD) -* | | and EXCLUSIVE4 | or EXCLUSIVE4 -* | | | (SHOULD NOT) -* no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 -* yes | no | GUARDED4 | GUARDED4 -* yes | yes | GUARDED4 | GUARDED4 -*/ +/* FIXME: check session persistence and pnfs flags. +* The nfsv4.1 spec requires the following semantics: +* +* Persistent | pNFS | Server REQUIRED | Client Allowed +* Reply Cache | server | | +* -------------+--------+-----------------+-------------------- +* no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 +* | | | (SHOULD) +* | | and EXCLUSIVE4 | or EXCLUSIVE4 +* | | | (SHOULD NOT) +* no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 +* yes | no | GUARDED4 | GUARDED4 +* yes | yes | GUARDED4 | GUARDED4 +*/ - current->fs->umask = open->op_umask; - status =nfsd4_create_file (rqstp, current_fh, *resfh, open); - current->fs->umask =0 ; + current->fs->umask = open->op_umask; + status =nfsd4_open_file (rqstp, current_fh, *resfh, open); + current->fs->umask =0 ; + +/* +* Following rfc 3530 14.2.16, and rfc 5661 18.16.4 +* use the returned bitmask to indicate which attributes +* we used to store the verifier: +*/ +if (open->op_create && status ==0 && +nfsd4_create_is_exclusive (open->op_createmode)) + open->op_bmval[1 ] |= (FATTR4_WORD1_TIME_ACCESS | +FATTR4_WORD1_TIME_MODIFY ); -/* -* Following rfc 3530 14.2.16, and rfc 5661 18.16.4 -* use the returned bitmask to indicate which attributes -* we used to store the verifier: -*/ -if (nfsd4_create_is_exclusive (open->op_createmode) && status ==0 ) - open->op_bmval[1 ] |= (FATTR4_WORD1_TIME_ACCESS | -FATTR4_WORD1_TIME_MODIFY ); - }else { - status =nfsd_lookup (rqstp, current_fh, - open->op_fname, open->op_fnamelen, *resfh); -/* NFSv4 protocol requires change attributes even though -* no change happened. -*/ -fh_fill_post_noop (current_fh); - }
Quoted 8 lines
fs/nfsd/nfs4proc.c do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, stru · line 472
Quoted 3 lines
fs/nfsd/nfs4proc.c +0
-0if (status) goto out; status =nfsd_check_obj_isreg (*resfh, cstate->minorversion);Logic bug: Pre-series, the non-create case takes do_open_lookup()'s else branch and succeeds; post-series,
do_open_lookup()callsnfsd4_open_file()unconditionally. EveryCLAIM_NULLopen of an existing file fails withNFS4ERR_EXIST.
yes - that is bad. I think
if (!open->op_created &&
- createmode == NFS4_CREATE_UNCHECKED) {
+ (open->op_create == NFS4_OPEN_NOCREATE ||
+ createmode == NFS4_CREATE_UNCHECKED)) {
/* NFSv4 protocol requires change attributes
* even though no change happened. */
is what I wanted to do. I've also move the clearing of ATTR_SIZE down to where we know we did created the file, so no trunc is needed.
Thanks a lot for the review.
NeilBrown
PATCH 18/18 VFS: remove dentry_create()
In reply to NeilBrownFrom: NeilBrown <[email protected]>
dentry_create() is no longer used and can be removed. vfs_lookup_open() is a better interface.
--- fs/namei.c | 80 ---------------------------------------------- include/linux/fs.h | 2 -- 2 files changed, 82 deletions(-)
fs/namei.c +0 -80
@@ -5067,86 +5067,6 @@ inline struct dentry *start_creating_user_path( }EXPORT_SYMBOL (start_creating_user_path); -/** -* dentry_create - Create and open a file -* @path: path to create -* @flags: O\_ flags -* @mode: mode bits for new file -* @cred: credentials to use -* -* Caller must hold the parent directory's lock, and have prepared -* a negative dentry, placed in @path->dentry, for the new file. -* -* Caller sets @path->mnt to the vfsmount of the filesystem where -* the new file is to be created. The parent directory and the -* negative dentry must reside on the same filesystem instance. -* -* On success, returns a ``struct file *``. Otherwise an ERR_PTR -* is returned. -*/ -struct file *dentry_create (struct path *path,int flags,umode_t mode, -const struct cred *cred) -{ - struct file *file __free(fput) = NULL; -struct dentry *dentry = path->dentry; -struct dentry *orig_dentry = dentry; -struct dentry *dir = dentry->d_parent; -struct inode *dir_inode =d_inode (dir); -struct mnt_idmap *idmap; -int error, create_error; - - file =alloc_empty_file (flags, cred); -if (IS_ERR (file)) -return file; - - idmap =mnt_idmap (path->mnt); - -if (dir_inode->i_op->atomic_open) { - path->dentry = dir; - mode =vfs_prepare_mode (idmap, dir_inode, mode,S_IALLUGO ,S_IFREG ); - - create_error =may_o_create (idmap, path, dentry, mode); -if (create_error) - flags &= ~O_CREAT ; - -/* atomic_open will dput(dentry) on error */ -dget (orig_dentry); - dentry =atomic_open (path, dentry, file, flags, mode); - error =PTR_ERR_OR_ZERO (dentry); - -if (IS_ERR (dentry)) -/* keep the original */ - dentry = orig_dentry; -else -/* Drop the extra reference */ -dput (orig_dentry); - -if (unlikely (create_error) && error == -ENOENT ) - error = create_error; - -if (!error) { -if (file->f_mode &FMODE_CREATED ) -fsnotify_create (dir->d_inode, dentry); -if (file->f_mode &FMODE_OPENED ) -fsnotify_open (file); - } - - path->dentry = dentry; - - }else { - error =vfs_create (mnt_idmap (path->mnt), path->dentry, mode,NULL ); -if (!error) - error =vfs_open (path, file); -if (!error) - file->f_mode |=FMODE_CREATED ; - } -if (unlikely (error)) -return ERR_PTR (error); - -return no_free_ptr (file); -} -EXPORT_SYMBOL (dentry_create); -/** * vfs_mknod - create device node or file * @idmap: idmap of the mount the inode was found from
include/linux/fs.h +0 -2
@@ -2472,8 +2472,6 @@ struct file *dentry_open(const struct path *path, int flags, const struct cred *creds);struct file *dentry_open_nonotify (const struct path *path,int flags,const struct cred *cred); -struct file *dentry_create (struct path *path,int flags,umode_t mode, -const struct cred *cred);const struct path *backing_file_user_path (const struct file *f);#ifdef CONFIG_SECURITY
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
Christian Brauner
maintainerQuoted 16 lines · NeilBrown
My recent proposal for inverting the order between
inode_lock()on a parent dir and d_alloc_parallel()[1] missed that fact thatatomic_open()has two callers, and would have resulted in easy deadlocks from nfsd when re-exporting and NFS filesystem.I think the best way to fix this is to provide a richer interface for nfsd to use, which includes all the locking as well as
inode_operationscalls. This allows the nfsd behaviour to share more code with the system-call behaviour.This series refactors code between
lookup_open()andopen_last_lookups(), and uses the newlookup_open()to providevfs_lookup_open(). It then rearranges the code in nfsd so that it can easily usevfs_lookup_open()instead ofdentry_create(). Finallydentry_create()is removed.
Quoted 4 lines
This series is based on a merge of nfsd-testing, vfs-next/work.dcache, and vfs/vfs.fixes (though I can't see my "Fix possible failure to unlock.."[2] patch in there yet). So I probably will need to resubmit after a bunch of that has hit mainline - though a few of the patches
Yes, please resubmit.
Quoted 2 lines
This will conflict with the O_CREAT|O_DIRECTORY work so obviously we'll need to work out how to order them once we both have enough positive review.
I have that on my todo but somehow said todo keeps growing...