linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHES] finish_no_open() calling conventions change
@ 2025-09-17 23:24 Al Viro
  2025-09-17 23:27 ` [PATCH 1/9] allow finish_no_open(file, ERR_PTR(-E...)) Al Viro
  0 siblings, 1 reply; 12+ messages in thread
From: Al Viro @ 2025-09-17 23:24 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: v9fs, Miklos Szeredi, Andreas Gruenbacher, linux-nfs,
	Hans de Goede, linux-cifs

	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 in
git://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(-)

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/9] allow finish_no_open(file, ERR_PTR(-E...))
  2025-09-17 23:24 [PATCHES] finish_no_open() calling conventions change Al Viro
@ 2025-09-17 23:27 ` Al Viro
  2025-09-17 23:27   ` [PATCH 2/9] 9p: simplify v9fs_vfs_atomic_open() Al Viro
                     ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Al Viro @ 2025-09-17 23:27 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: v9fs, miklos, agruenba, linux-nfs, hansg, linux-cifs

... allowing any ->lookup() return value to be passed to it.

Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/open.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/open.c b/fs/open.c
index 9655158c3885..4890b13461c7 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -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;
 }
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/9] 9p: simplify v9fs_vfs_atomic_open()
  2025-09-17 23:27 ` [PATCH 1/9] allow finish_no_open(file, ERR_PTR(-E...)) Al Viro
@ 2025-09-17 23:27   ` Al Viro
  2025-09-17 23:27   ` [PATCH 3/9] 9p: simplify v9fs_vfs_atomic_open_dotl() Al Viro
                     ` (6 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Al Viro @ 2025-09-17 23:27 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: v9fs, miklos, agruenba, linux-nfs, hansg, linux-cifs

if 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.

Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/9p/vfs_inode.c | 34 ++++++++++++----------------------
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 399d455d50d6..d0c77ec31b1d 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -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;
 }
 
 /**
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/9] 9p: simplify v9fs_vfs_atomic_open_dotl()
  2025-09-17 23:27 ` [PATCH 1/9] allow finish_no_open(file, ERR_PTR(-E...)) Al Viro
  2025-09-17 23:27   ` [PATCH 2/9] 9p: simplify v9fs_vfs_atomic_open() Al Viro
@ 2025-09-17 23:27   ` Al Viro
  2025-09-17 23:27   ` [PATCH 4/9] simplify cifs_atomic_open() Al Viro
                     ` (5 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Al Viro @ 2025-09-17 23:27 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: v9fs, miklos, agruenba, linux-nfs, hansg, linux-cifs

again, preexisting aliases will always be positive

Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/9p/vfs_inode_dotl.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c
index 5b5fda617b80..be297e335468 100644
--- a/fs/9p/vfs_inode_dotl.c
+++ b/fs/9p/vfs_inode_dotl.c
@@ -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;
 }
 
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/9] simplify cifs_atomic_open()
  2025-09-17 23:27 ` [PATCH 1/9] allow finish_no_open(file, ERR_PTR(-E...)) Al Viro
  2025-09-17 23:27   ` [PATCH 2/9] 9p: simplify v9fs_vfs_atomic_open() Al Viro
  2025-09-17 23:27   ` [PATCH 3/9] 9p: simplify v9fs_vfs_atomic_open_dotl() Al Viro
@ 2025-09-17 23:27   ` Al Viro
  2025-09-17 23:27   ` [PATCH 5/9] simplify vboxsf_dir_atomic_open() Al Viro
                     ` (4 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Al Viro @ 2025-09-17 23:27 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: v9fs, miklos, agruenba, linux-nfs, hansg, linux-cifs

now that finish_no_open() does the right thing if it's given ERR_PTR() as
dentry...

Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/smb/client/dir.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/fs/smb/client/dir.c b/fs/smb/client/dir.c
index 5223edf6d11a..47710aa13822 100644
--- a/fs/smb/client/dir.c
+++ b/fs/smb/client/dir.c
@@ -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();
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/9] simplify vboxsf_dir_atomic_open()
  2025-09-17 23:27 ` [PATCH 1/9] allow finish_no_open(file, ERR_PTR(-E...)) Al Viro
                     ` (2 preceding siblings ...)
  2025-09-17 23:27   ` [PATCH 4/9] simplify cifs_atomic_open() Al Viro
@ 2025-09-17 23:27   ` Al Viro
  2025-09-18  7:34     ` Hans de Goede
  2025-09-17 23:27   ` [PATCH 6/9] simplify nfs_atomic_open_v23() Al Viro
                     ` (3 subsequent siblings)
  7 siblings, 1 reply; 12+ messages in thread
From: Al Viro @ 2025-09-17 23:27 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: v9fs, miklos, agruenba, linux-nfs, hansg, linux-cifs

similar to 9p et.al.

Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/vboxsf/dir.c | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/fs/vboxsf/dir.c b/fs/vboxsf/dir.c
index 770e29ec3557..42bedc4ec7af 100644
--- a/fs/vboxsf/dir.c
+++ b/fs/vboxsf/dir.c
@@ -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)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 6/9] simplify nfs_atomic_open_v23()
  2025-09-17 23:27 ` [PATCH 1/9] allow finish_no_open(file, ERR_PTR(-E...)) Al Viro
                     ` (3 preceding siblings ...)
  2025-09-17 23:27   ` [PATCH 5/9] simplify vboxsf_dir_atomic_open() Al Viro
@ 2025-09-17 23:27   ` Al Viro
  2025-09-17 23:27   ` [PATCH 7/9] simplify fuse_atomic_open() Al Viro
                     ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Al Viro @ 2025-09-17 23:27 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: v9fs, miklos, agruenba, linux-nfs, hansg, linux-cifs

1) 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.

Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/nfs/dir.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index d81217923936..c8dd1d0b8d85 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -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);
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 7/9] simplify fuse_atomic_open()
  2025-09-17 23:27 ` [PATCH 1/9] allow finish_no_open(file, ERR_PTR(-E...)) Al Viro
                     ` (4 preceding siblings ...)
  2025-09-17 23:27   ` [PATCH 6/9] simplify nfs_atomic_open_v23() Al Viro
@ 2025-09-17 23:27   ` Al Viro
  2025-09-19  9:16     ` Miklos Szeredi
  2025-09-17 23:27   ` [PATCH 8/9] simplify gfs2_atomic_open() Al Viro
  2025-09-17 23:27   ` [PATCH 9/9] slightly simplify nfs_atomic_open() Al Viro
  7 siblings, 1 reply; 12+ messages in thread
From: Al Viro @ 2025-09-17 23:27 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: v9fs, miklos, agruenba, linux-nfs, hansg, linux-cifs

Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/fuse/dir.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 2d817d7cab26..d3076bfddb89 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -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);
 }
 
 /*
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 8/9] simplify gfs2_atomic_open()
  2025-09-17 23:27 ` [PATCH 1/9] allow finish_no_open(file, ERR_PTR(-E...)) Al Viro
                     ` (5 preceding siblings ...)
  2025-09-17 23:27   ` [PATCH 7/9] simplify fuse_atomic_open() Al Viro
@ 2025-09-17 23:27   ` Al Viro
  2025-09-17 23:27   ` [PATCH 9/9] slightly simplify nfs_atomic_open() Al Viro
  7 siblings, 0 replies; 12+ messages in thread
From: Al Viro @ 2025-09-17 23:27 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: v9fs, miklos, agruenba, linux-nfs, hansg, linux-cifs

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.

Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/gfs2/inode.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 8760e7e20c9d..8a7ed80d9f2d 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -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;
 
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 9/9] slightly simplify nfs_atomic_open()
  2025-09-17 23:27 ` [PATCH 1/9] allow finish_no_open(file, ERR_PTR(-E...)) Al Viro
                     ` (6 preceding siblings ...)
  2025-09-17 23:27   ` [PATCH 8/9] simplify gfs2_atomic_open() Al Viro
@ 2025-09-17 23:27   ` Al Viro
  7 siblings, 0 replies; 12+ messages in thread
From: Al Viro @ 2025-09-17 23:27 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: v9fs, miklos, agruenba, linux-nfs, hansg, linux-cifs

Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/nfs/dir.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index c8dd1d0b8d85..5f7d9be6f022 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -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);
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 5/9] simplify vboxsf_dir_atomic_open()
  2025-09-17 23:27   ` [PATCH 5/9] simplify vboxsf_dir_atomic_open() Al Viro
@ 2025-09-18  7:34     ` Hans de Goede
  0 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2025-09-18  7:34 UTC (permalink / raw)
  To: Al Viro, linux-fsdevel; +Cc: v9fs, miklos, agruenba, linux-nfs, linux-cifs

Hi,

On 18-Sep-25 1:27 AM, Al Viro wrote:
> similar to 9p et.al.
> 
> Reviewed-by: NeilBrown <neil@brown.name>
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hansg@kernel.org>

Regards,

Hans



> ---
>  fs/vboxsf/dir.c | 25 +++++++++----------------
>  1 file changed, 9 insertions(+), 16 deletions(-)
> 
> diff --git a/fs/vboxsf/dir.c b/fs/vboxsf/dir.c
> index 770e29ec3557..42bedc4ec7af 100644
> --- a/fs/vboxsf/dir.c
> +++ b/fs/vboxsf/dir.c
> @@ -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)


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 7/9] simplify fuse_atomic_open()
  2025-09-17 23:27   ` [PATCH 7/9] simplify fuse_atomic_open() Al Viro
@ 2025-09-19  9:16     ` Miklos Szeredi
  0 siblings, 0 replies; 12+ messages in thread
From: Miklos Szeredi @ 2025-09-19  9:16 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-fsdevel, v9fs, agruenba, linux-nfs, hansg, linux-cifs

On Thu, 18 Sept 2025 at 01:27, Al Viro <viro@zeniv.linux.org.uk> 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.

> Reviewed-by: NeilBrown <neil@brown.name>
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Reviewed-by: Miklos Szeredi <mszeredi@redhat.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-09-19  9:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-17 23:24 [PATCHES] finish_no_open() calling conventions change Al Viro
2025-09-17 23:27 ` [PATCH 1/9] allow finish_no_open(file, ERR_PTR(-E...)) Al Viro
2025-09-17 23:27   ` [PATCH 2/9] 9p: simplify v9fs_vfs_atomic_open() Al Viro
2025-09-17 23:27   ` [PATCH 3/9] 9p: simplify v9fs_vfs_atomic_open_dotl() Al Viro
2025-09-17 23:27   ` [PATCH 4/9] simplify cifs_atomic_open() Al Viro
2025-09-17 23:27   ` [PATCH 5/9] simplify vboxsf_dir_atomic_open() Al Viro
2025-09-18  7:34     ` Hans de Goede
2025-09-17 23:27   ` [PATCH 6/9] simplify nfs_atomic_open_v23() Al Viro
2025-09-17 23:27   ` [PATCH 7/9] simplify fuse_atomic_open() Al Viro
2025-09-19  9:16     ` Miklos Szeredi
2025-09-17 23:27   ` [PATCH 8/9] simplify gfs2_atomic_open() Al Viro
2025-09-17 23:27   ` [PATCH 9/9] slightly simplify nfs_atomic_open() Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).