finish_no_open() calling conventions change
Subsystems (9)
Al Viro
maintainerPATCH 1/1 finish_no_open() calling conventions change
finish_no_open() dentry argument has the same conventions as
->lookup() return value - NULL for "use the dentry we expected to open", pointer to dentry - "consume a reference to this preexisting alias". What it does not accept is the third variant of ->lookup() - ERR_PTR(err). Making finish_no_open() accept that as well (returning err in that case) simplifies life in ->atomic_open(), especially since the "got a preexisting alias" is exactly the case when we end up with a positive dentry.
Branch (-rc5-based) is ingit://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git work.finish_no_open Individual patches in followups.
Please, review - if there's no objections, to -next it goes.
Shortlog:
allow finish_no_open(file, ERR_PTR(-E...))
9p: simplify v9fs_vfs_atomic_open()
9p: simplify v9fs_vfs_atomic_open_dotl()
simplify cifs_atomic_open()
simplify vboxsf_dir_atomic_open()
simplify nfs_atomic_open_v23()
simplify fuse_atomic_open()
simplify gfs2_atomic_open()
slightly simplify nfs_atomic_open()
Diffstat:
fs/9p/vfs_inode.c | 34 ++++++++++++---------------------- fs/9p/vfs_inode_dotl.c | 15 +++++---------- fs/fuse/dir.c | 21 +++++++-------------- fs/gfs2/inode.c | 26 +++++++++----------------- fs/nfs/dir.c | 18 +++++------------- fs/open.c | 10 ++++++---- fs/smb/client/dir.c | 8 +------- fs/vboxsf/dir.c | 25 +++++++++---------------- 8 files changed, 54 insertions(+), 103 deletions(-)
Al Viro
maintainerPATCH 6/9 simplify nfs_atomic_open_v23()
In reply to Al Viro1) finish_no_open() takes ERR_PTR() as dentry now.
2) caller of ->atomic_open() will call d_lookup_done() itself, no need to do it here.
--- fs/nfs/dir.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
fs/nfs/dir.c +5 -11
@@ -2260,7 +2260,7 @@ int nfs_atomic_open_v23(struct inode *dir, struct dentry *dentry, struct file *file, unsigned int open_flags, umode_t mode) { - + struct dentry *res = NULL;/* Same as look+open from lookup_open(), but with different O_TRUNC * handling. */
@@ -2275,21 +2275,15 @@ int nfs_atomic_open_v23(struct inode *dir, struct dentry *dentry,if (error)return error;return finish_open (file, dentry,NULL ); - }else if (d_in_lookup (dentry)) { + } +if (d_in_lookup (dentry)) {/* The only flags nfs_lookup considers are * LOOKUP_EXCL and LOOKUP_RENAME_TARGET, and * we want those to be zero so the lookup isn't skipped. */ -struct dentry *res =nfs_lookup (dir, dentry,0 ); - -d_lookup_done (dentry); -if (unlikely (res)) { -if (IS_ERR (res)) -return PTR_ERR (res); -return finish_no_open (file, res); - } + res =nfs_lookup (dir, dentry,0 ); } -return finish_no_open (file,NULL ); +return finish_no_open (file, res); }EXPORT_SYMBOL_GPL (nfs_atomic_open_v23);
Signature · 1 line
2.47.3
Al Viro
maintainerPATCH 2/9 9p: simplify v9fs_vfs_atomic_open()
In reply to Al Viroif v9fs_vfs_lookup() returns a preexisting alias, it is guaranteed to be positive. IOW, in that case we will immediately return finish_no_open(), leaving only the case res == NULL past that point.
--- fs/9p/vfs_inode.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-)
fs/9p/vfs_inode.c +12 -22
@@ -768,22 +768,18 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,struct v9fs_inode __maybe_unused *v9inode;struct v9fs_session_info *v9ses;struct p9_fid *fid; -struct dentry *res =NULL ;struct inode *inode;int p9_omode;if (d_in_lookup (dentry)) { - res =v9fs_vfs_lookup (dir, dentry,0 ); -if (IS_ERR (res)) -return PTR_ERR (res); - -if (res) - dentry = res; +struct dentry *res =v9fs_vfs_lookup (dir, dentry,0 ); +if (res ||d_really_is_positive (dentry)) +return finish_no_open (file, res); }/* Only creates */ -if (!(flags &O_CREAT ) ||d_really_is_positive (dentry)) -return finish_no_open (file, res); +if (!(flags &O_CREAT )) +return finish_no_open (file,NULL ); v9ses =v9fs_inode2v9ses (dir); perm =unixmode2p9mode (v9ses, mode);
@@ -795,17 +791,17 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry, "write-only file with writeback enabled, creating w/ O_RDWR\n"); } fid =v9fs_create (v9ses, dir, dentry,NULL , perm, p9_omode); -if (IS_ERR (fid)) { - err =PTR_ERR (fid); - goto error; - } +if (IS_ERR (fid)) +return PTR_ERR (fid);v9fs_invalidate_inode_attr (dir); inode =d_inode (dentry); v9inode =V9FS_I (inode); err =finish_open (file, dentry, generic_file_open); -if (err) - goto error; +if (unlikely (err)) { +p9_fid_put (fid); +return err; + } file->private_data = fid;#ifdef CONFIG_9P_FSCACHE
@@ -818,13 +814,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,v9fs_open_fid_add (inode, &fid); file->f_mode |=FMODE_CREATED ; -out: -dput (res); -return err; - -error: -p9_fid_put (fid); - goto out; +return 0 ; }/**
Signature · 1 line
2.47.3
Al Viro
maintainerPATCH 3/9 9p: simplify v9fs_vfs_atomic_open_dotl()
In reply to Al Viroagain, preexisting aliases will always be positive
--- fs/9p/vfs_inode_dotl.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
fs/9p/vfs_inode_dotl.c +5 -10
@@ -238,20 +238,16 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,struct p9_fid *dfid =NULL , *ofid =NULL ;struct v9fs_session_info *v9ses;struct posix_acl *pacl =NULL , *dacl =NULL ; -struct dentry *res =NULL ;if (d_in_lookup (dentry)) { - res =v9fs_vfs_lookup (dir, dentry,0 ); -if (IS_ERR (res)) -return PTR_ERR (res); - -if (res) - dentry = res; +struct dentry *res =v9fs_vfs_lookup (dir, dentry,0 ); +if (res ||d_really_is_positive (dentry)) +return finish_no_open (file, res); }/* Only creates */ -if (!(flags &O_CREAT ) ||d_really_is_positive (dentry)) -return finish_no_open (file, res); +if (!(flags &O_CREAT )) +return finish_no_open (file,NULL ); v9ses =v9fs_inode2v9ses (dir);
@@ -337,7 +333,6 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,p9_fid_put (ofid);p9_fid_put (fid);v9fs_put_acl (dacl, pacl); -dput (res);return err; }
Signature · 1 line
2.47.3
Al Viro
maintainerPATCH 4/9 simplify cifs_atomic_open()
In reply to Al Vironow that finish_no_open() does the right thing if it's given ERR_PTR() as dentry...
--- fs/smb/client/dir.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
fs/smb/client/dir.c +1 -7
@@ -484,8 +484,6 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,* in network traffic in the other paths. */ if (!(oflags &O_CREAT )) { -struct dentry *res; -/* * Check for hashed negative dentry. We have already revalidated * the dentry and it is fine. No need to perform another lookup.
@@ -493,11 +491,7 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,if (!d_in_lookup (direntry))return -ENOENT ; - res =cifs_lookup (inode, direntry,0 ); -if (IS_ERR (res)) -return PTR_ERR (res); - -return finish_no_open (file, res); +return finish_no_open (file,cifs_lookup (inode, direntry,0 )); } xid =get_xid ();
Signature · 1 line
2.47.3
Al Viro
maintainerPATCH 5/9 simplify vboxsf_dir_atomic_open()
In reply to Al Virosimilar to 9p et.al.
--- fs/vboxsf/dir.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
fs/vboxsf/dir.c +9 -16
@@ -315,46 +315,39 @@ static int vboxsf_dir_atomic_open(struct inode *parent, struct dentry *dentry, {struct vboxsf_sbi *sbi =VBOXSF_SBI (parent->i_sb);struct vboxsf_handle *sf_handle; -struct dentry *res =NULL ;u64 handle;int err;if (d_in_lookup (dentry)) { - res =vboxsf_dir_lookup (parent, dentry,0 ); -if (IS_ERR (res)) -return PTR_ERR (res); - -if (res) - dentry = res; +struct dentry *res =vboxsf_dir_lookup (parent, dentry,0 ); +if (res ||d_really_is_positive (dentry)) +return finish_no_open (file, res); }/* Only creates */ -if (!(flags &O_CREAT ) ||d_really_is_positive (dentry)) -return finish_no_open (file, res); +if (!(flags &O_CREAT )) +return finish_no_open (file,NULL ); err =vboxsf_dir_create (parent, dentry, mode, false, flags &O_EXCL , &handle);if (err) - goto out; +return err; sf_handle =vboxsf_create_sf_handle (d_inode (dentry), handle,SHFL_CF_ACCESS_READWRITE );if (IS_ERR (sf_handle)) {vboxsf_close (sbi->root, handle); - err =PTR_ERR (sf_handle); - goto out; +return PTR_ERR (sf_handle); } err =finish_open (file, dentry, generic_file_open);if (err) {/* This also closes the handle passed to vboxsf_create_sf_handle() */ vboxsf_release_sf_handle (d_inode (dentry), sf_handle); - goto out; +return err; } file->private_data = sf_handle; file->f_mode |=FMODE_CREATED ; -out: -dput (res); -return err; +return 0 ; }static int vboxsf_dir_unlink (struct inode *parent,struct dentry *dentry)
Signature · 1 line
2.47.3
Al Viro
maintainerPATCH 7/9 simplify fuse_atomic_open()
In reply to Al Viro--- fs/fuse/dir.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)
fs/fuse/dir.c +7 -14
@@ -739,22 +739,18 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,int err;struct mnt_idmap *idmap =file_mnt_idmap (file);struct fuse_conn *fc =get_fuse_conn (dir); -struct dentry *res =NULL ;if (fuse_is_bad (dir))return -EIO ;if (d_in_lookup (entry)) { - res =fuse_lookup (dir, entry,0 ); -if (IS_ERR (res)) -return PTR_ERR (res); - -if (res) - entry = res; +struct dentry *res =fuse_lookup (dir, entry,0 ); +if (res ||d_really_is_positive (entry)) +return finish_no_open (file, res); } -if (!(flags &O_CREAT ) ||d_really_is_positive (entry)) - goto no_open; +if (!(flags &O_CREAT )) +return finish_no_open (file,NULL );/* Only creates */ file->f_mode |=FMODE_CREATED ;
@@ -768,16 +764,13 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry, goto mknod; }else if (err == -EEXIST )fuse_invalidate_entry (entry); -out_dput: -dput (res);return err; mknod: err =fuse_mknod (idmap, dir, entry, mode,0 );if (err) - goto out_dput; -no_open: -return finish_no_open (file, res); +return err; +return finish_no_open (file,NULL ); }/*
Signature · 1 line
2.47.3
Al Viro
maintainerPATCH 9/9 slightly simplify nfs_atomic_open()
In reply to Al Viro--- fs/nfs/dir.c | 2 -- 1 file changed, 2 deletions(-)
fs/nfs/dir.c +0 -2
@@ -2198,8 +2198,6 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,else dput (dentry); } -if (IS_ERR (res)) -return PTR_ERR (res);return finish_no_open (file, res); }EXPORT_SYMBOL_GPL (nfs_atomic_open);
Signature · 1 line
2.47.3
Al Viro
maintainerPATCH 1/9 allow finish_no_open(file, ERR_PTR(-E...))
In reply to Al Viro... allowing any ->lookup() return value to be passed to it.
--- fs/open.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fs/open.c +6 -4
@@ -1059,18 +1059,20 @@ EXPORT_SYMBOL(finish_open);* finish_no_open - finish ->atomic_open() without opening the file * * @file: file pointer -* @dentry: dentry or NULL (as returned from ->lookup()) +* @dentry: dentry, ERR_PTR(-E...) or NULL (as returned from ->lookup()) * -* This can be used to set the result of a successful lookup in ->atomic_open(). +* This can be used to set the result of a lookup in ->atomic_open(). * * NB: unlike finish_open() this function does consume the dentry reference and * the caller need not dput() it. * -* Returns "0" which must be the return value of ->atomic_open() after having -* called this function. +* Returns 0 or -E..., which must be the return value of ->atomic_open() after +* having called this function. */ int finish_no_open (struct file *file,struct dentry *dentry) { +if (IS_ERR (dentry)) +return PTR_ERR (dentry); file->f_path.dentry = dentry;return 0 ; }
Signature · 1 line
2.47.3
Al Viro
maintainerPATCH 8/9 simplify gfs2_atomic_open()
the difference from 9p et.al. is that on gfs2 the lookup side might end up opening the file. That's what the FMODE_OPENED check there is about - and it might actually be seen with finish_open() having failed, if it fails late enough.
--- fs/gfs2/inode.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-)
fs/gfs2/inode.c +9 -17
@@ -1368,27 +1368,19 @@ static int gfs2_atomic_open(struct inode *dir, struct dentry *dentry, struct file *file, unsigned flags, umode_t mode) { - struct dentry *d; bool excl = !!(flags & O_EXCL); -if (!d_in_lookup (dentry)) - goto skip_lookup; - - d =__gfs2_lookup (dir, dentry, file); -if (IS_ERR (d)) -return PTR_ERR (d); -if (d !=NULL ) - dentry = d; -if (d_really_is_positive (dentry)) { -if (!(file->f_mode &FMODE_OPENED )) +if (d_in_lookup (dentry)) { +struct dentry *d =__gfs2_lookup (dir, dentry, file); +if (file->f_mode &FMODE_OPENED ) { +if (IS_ERR (d)) +return PTR_ERR (d); +dput (d); +return excl && (flags &O_CREAT ) ? -EEXIST :0 ; + } +if (d ||d_really_is_positive (dentry))return finish_no_open (file, d); -dput (d); -return excl && (flags &O_CREAT ) ? -EEXIST :0 ; } - -BUG_ON (d !=NULL ); - -skip_lookup:if (!(flags &O_CREAT ))return -ENOENT ;
Signature · 1 line
2.47.3
Re: [PATCH 5/9] simplify vboxsf_dir_atomic_open()
In reply to Al ViroHi,
Quoted 4 lines · Al Viro
similar to 9p et.al.
Reviewed-by NeilBrown <[email protected]>Signed-off-by Al Viro <[email protected]>
Thanks, patch looks good to me:
Regards,
Hans
Quoted 64 lines
--- fs/vboxsf/dir.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)fs/vboxsf/dir.c +9
-16@@ -315,46 +315,39 @@ static int vboxsf_dir_atomic_open(struct inode *parent, struct dentry *dentry, {struct vboxsf_sbi *sbi =VBOXSF_SBI (parent->i_sb);struct vboxsf_handle *sf_handle; -struct dentry *res =NULL ;u64 handle;int err;if (d_in_lookup (dentry)) { - res =vboxsf_dir_lookup (parent, dentry,0 ); -if (IS_ERR (res)) -return PTR_ERR (res); - -if (res) - dentry = res; +struct dentry *res =vboxsf_dir_lookup (parent, dentry,0 ); +if (res ||d_really_is_positive (dentry)) +return finish_no_open (file, res); }/* Only creates */ -if (!(flags &O_CREAT ) ||d_really_is_positive (dentry)) -return finish_no_open (file, res); +if (!(flags &O_CREAT )) +return finish_no_open (file,NULL ); err =vboxsf_dir_create (parent, dentry, mode, false, flags &O_EXCL , &handle);if (err) - goto out; +return err; sf_handle =vboxsf_create_sf_handle (d_inode (dentry), handle,SHFL_CF_ACCESS_READWRITE );if (IS_ERR (sf_handle)) {vboxsf_close (sbi->root, handle); - err =PTR_ERR (sf_handle); - goto out; +return PTR_ERR (sf_handle); } err =finish_open (file, dentry, generic_file_open);if (err) {/* This also closes the handle passed to vboxsf_create_sf_handle() */ vboxsf_release_sf_handle (d_inode (dentry), sf_handle); - goto out; +return err; } file->private_data = sf_handle; file->f_mode |=FMODE_CREATED ; -out: -dput (res); -return err; +return 0 ; }static int vboxsf_dir_unlink (struct inode *parent,struct dentry *dentry)
Re: [PATCH 7/9] simplify fuse_atomic_open()
In reply to Al ViroOn Thu, 18 Sept 2025 at 01:27, Al Viro <[email protected]> wrote:
Some explanation about the dput() removal would be useful, e.g.:
Non-null res implies either an error or a positive dentry, hence the dput(res) cleanup is unnecessary, since at that point res will always be NULL.
Quoted 2 lines
Reviewed-by NeilBrown <[email protected]>Signed-off-by Al Viro <[email protected]>