FILESYSTEM IN USERSPACE (FUSE) development
 help / color / mirror / Atom feed
From: Joanne Koong <joannelkoong@gmail.com>
To: miklos@szeredi.hu, fuse-devel@lists.linux.dev
Cc: Amir Goldstein <amir73il@gmail.com>
Subject: [PATCH v1 04/13] fuse: clean up fuse_dentry_revalidate()
Date: Thu, 23 Apr 2026 18:16:37 -0700	[thread overview]
Message-ID: <20260424011646.457682-5-joannelkoong@gmail.com> (raw)
In-Reply-To: <20260424011646.457682-1-joannelkoong@gmail.com>

Remove gotos with direct returns and flatten nested if/else structure.
No functional changes.

Suggested-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
Cc: Amir Goldstein <amir73il@gmail.com>
---
 fs/fuse/dir.c | 114 ++++++++++++++++++++++++--------------------------
 1 file changed, 54 insertions(+), 60 deletions(-)

diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 112d979c49c5..c5b3cb001147 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -386,72 +386,32 @@ static int fuse_dentry_revalidate(struct inode *dir, const struct qstr *name,
 				  struct dentry *entry, unsigned int flags)
 {
 	struct inode *inode;
-	struct fuse_mount *fm;
 	struct fuse_conn *fc;
 	struct fuse_inode *fi;
+	struct fuse_entry_out outarg;
+	struct fuse_forget_link *forget;
+	FUSE_ARGS(args);
+	bool automount_changed;
+	u64 attr_version;
+	bool need_reval;
 	int ret;
 
 	fc = get_fuse_conn_super(dir->i_sb);
 	if (entry->d_time < atomic_read(&fc->epoch))
-		goto invalid;
+		return 0;
 
 	inode = d_inode_rcu(entry);
 	if (inode && fuse_is_bad(inode))
-		goto invalid;
-	else if (time_before64(fuse_dentry_time(entry), get_jiffies_64()) ||
-		 (flags & (LOOKUP_EXCL | LOOKUP_REVAL | LOOKUP_RENAME_TARGET))) {
-		struct fuse_entry_out outarg;
-		FUSE_ARGS(args);
-		struct fuse_forget_link *forget;
-		u64 attr_version;
-
-		/* For negative dentries, always do a fresh lookup */
-		if (!inode)
-			goto invalid;
-
-		ret = -ECHILD;
-		if (flags & LOOKUP_RCU)
-			goto out;
+		return 0;
 
-		fm = get_fuse_mount(inode);
+	need_reval = time_before64(fuse_dentry_time(entry), get_jiffies_64()) ||
+		 (flags & (LOOKUP_EXCL | LOOKUP_REVAL | LOOKUP_RENAME_TARGET));
 
-		forget = fuse_alloc_forget();
-		ret = -ENOMEM;
-		if (!forget)
-			goto out;
-
-		attr_version = fuse_get_attr_version(fm->fc);
-
-		fuse_lookup_init(&args, get_node_id(dir), name, &outarg);
-		ret = fuse_simple_request(fm, &args);
-		/* Zero nodeid is same as -ENOENT */
-		if (!ret && !outarg.nodeid)
-			ret = -ENOENT;
-		if (!ret) {
-			fi = get_fuse_inode(inode);
-			if (outarg.nodeid != get_node_id(inode) ||
-			    (bool) IS_AUTOMOUNT(inode) != (bool) (outarg.attr.flags & FUSE_ATTR_SUBMOUNT)) {
-				fuse_chan_queue_forget(fm->fc->chan, forget,
-						  outarg.nodeid, 1);
-				goto invalid;
-			}
-			spin_lock(&fi->lock);
-			fi->nlookup++;
-			spin_unlock(&fi->lock);
-		}
-		kfree(forget);
-		if (ret == -ENOMEM || ret == -EINTR)
-			goto out;
-		if (ret || fuse_invalid_attr(&outarg.attr) ||
-		    fuse_stale_inode(inode, outarg.generation, &outarg.attr))
-			goto invalid;
+	/* For negative dentries that need revalidation, always do a fresh lookup */
+	if (!inode)
+		return need_reval ? 0 : 1;
 
-		forget_all_cached_acls(inode);
-		fuse_change_attributes(inode, &outarg.attr, NULL,
-				       ATTR_TIMEOUT(&outarg),
-				       attr_version);
-		fuse_change_entry_timeout(entry, &outarg);
-	} else if (inode) {
+	if (!need_reval) {
 		fi = get_fuse_inode(inode);
 		if (flags & LOOKUP_RCU) {
 			if (test_bit(FUSE_I_INIT_RDPLUS, &fi->state))
@@ -459,14 +419,48 @@ static int fuse_dentry_revalidate(struct inode *dir, const struct qstr *name,
 		} else if (test_and_clear_bit(FUSE_I_INIT_RDPLUS, &fi->state)) {
 			fuse_advise_use_readdirplus(dir);
 		}
+
+		return 1;
 	}
-	ret = 1;
-out:
-	return ret;
 
-invalid:
-	ret = 0;
-	goto out;
+	if (flags & LOOKUP_RCU)
+		return -ECHILD;
+
+	forget = fuse_alloc_forget();
+	if (!forget)
+		return -ENOMEM;
+
+	attr_version = fuse_get_attr_version(fc);
+
+	fuse_lookup_init(&args, get_node_id(dir), name, &outarg);
+	ret = fuse_simple_request(get_fuse_mount(inode), &args);
+	if (ret || !outarg.nodeid) {
+		kfree(forget);
+		return (ret == -ENOMEM || ret == -EINTR) ? ret : 0;
+	}
+
+	automount_changed =
+		!!IS_AUTOMOUNT(inode) != !!(outarg.attr.flags & FUSE_ATTR_SUBMOUNT);
+
+	if (outarg.nodeid != get_node_id(inode) || automount_changed) {
+		fuse_chan_queue_forget(fc->chan, forget, outarg.nodeid, 1);
+		return 0;
+	}
+	fi = get_fuse_inode(inode);
+	spin_lock(&fi->lock);
+	fi->nlookup++;
+	spin_unlock(&fi->lock);
+
+	kfree(forget);
+	if (fuse_invalid_attr(&outarg.attr) ||
+	    fuse_stale_inode(inode, outarg.generation, &outarg.attr))
+		return 0;
+
+	forget_all_cached_acls(inode);
+	fuse_change_attributes(inode, &outarg.attr, NULL, ATTR_TIMEOUT(&outarg),
+			       attr_version);
+	fuse_change_entry_timeout(entry, &outarg);
+	return 1;
 }
 
 static int fuse_dentry_init(struct dentry *dentry)
-- 
2.52.0


  parent reply	other threads:[~2026-04-24  1:18 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-24  1:16 [PATCH v1 00/13] fuse: dir.c cleanups Joanne Koong
2026-04-24  1:16 ` [PATCH v1 01/13] fuse: fix missing forget requests in error paths Joanne Koong
2026-04-24  8:18   ` Amir Goldstein
2026-04-24 17:43     ` Joanne Koong
2026-04-24  1:16 ` [PATCH v1 02/13] fuse: clean up fuse_lookup_name() Joanne Koong
2026-04-24  1:16 ` [PATCH v1 03/13] fuse: clean up fuse_lookup() Joanne Koong
2026-04-24  1:16 ` Joanne Koong [this message]
2026-04-24  8:20   ` [PATCH v1 04/13] fuse: clean up fuse_dentry_revalidate() Amir Goldstein
2026-04-24  1:16 ` [PATCH v1 05/13] fuse: clean up fuse_create_open() Joanne Koong
2026-04-24  1:16 ` [PATCH v1 06/13] fuse: clean up fuse_rename2() Joanne Koong
2026-04-24  1:16 ` [PATCH v1 07/13] fuse: clean up fuse_time_to_jiffies() Joanne Koong
2026-04-24  1:16 ` [PATCH v1 08/13] fuse: clean up fuse_link() Joanne Koong
2026-04-24  1:16 ` [PATCH v1 09/13] fuse: clean up fuse_do_getattr() Joanne Koong
2026-04-24  1:16 ` [PATCH v1 10/13] fuse: clean up fuse_update_get_attr() Joanne Koong
2026-04-24  1:16 ` [PATCH v1 11/13] fuse: clean up fuse_get_link() Joanne Koong
2026-04-24  1:16 ` [PATCH v1 12/13] fuse: clean up fuse_dir_open() Joanne Koong
2026-04-24  1:16 ` [PATCH v1 13/13] fuse: clean up setattr() Joanne Koong
2026-04-24  7:51 ` [PATCH v1 00/13] fuse: dir.c cleanups Amir Goldstein
2026-04-24 17:27   ` Joanne Koong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260424011646.457682-5-joannelkoong@gmail.com \
    --to=joannelkoong@gmail.com \
    --cc=amir73il@gmail.com \
    --cc=fuse-devel@lists.linux.dev \
    --cc=miklos@szeredi.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox