Skip to contentSkip to conversation

fuse: fix inconsistent status between faccess and mkdir

PATCH Superseded Fengnan Chang 2 participants 3 messages May 14, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fuse: fix inconsistent status between faccess and mkdir

since FUSE caches dentries and attributes with separate timeout, It may happen that checking the permission returns -ENOENT, but because the dentries cache has not timed out, creating the file returns -EEXIST. Fix this by when return ENOENT, mark the entry as stale.

---
 fs/fuse/dir.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
fs/fuse/dir.c +16 -0
index 06a18700a845..154dd4578762 100644
@@ -1065,6 +1065,14 @@ static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
 				fuse_fillattr(inode, &outarg.attr, stat);
 		}
 	}
+	if (err == -ENOENT) {
+		struct dentry *entry;
+
+		entry = d_obtain_alias(inode);
+		if (!IS_ERR(entry) && get_node_id(inode) != FUSE_ROOT_ID)
+			fuse_invalidate_entry_cache(entry);
+	}
+
 	return err;
 }
 
@@ -1226,6 +1234,14 @@ static int fuse_access(struct inode *inode, int mask)
 		fm->fc->no_access = 1;
 		err = 0;
 	}
+	if (err == -ENOENT) {
+		struct dentry *entry;
+
+		entry = d_obtain_alias(inode);
+		if (!IS_ERR(entry) && get_node_id(inode) != FUSE_ROOT_ID)
+			fuse_invalidate_entry_cache(entry);
+	}
+
 	return err;
 }
 
Signature · 1 line
2.29.0
#1 lore raw

fs/fuse/dir.c static int fuse_do_getattr(struct inode *inode, struct kstat *stat, · line 1071

Quoted 9 lines · Fengnan Chang

+++ b/fs/fuse/dir.c

fs/fuse/dir.c +4 -0
@@ -1065,6 +1065,14 @@ static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
 				fuse_fillattr(inode, &outarg.attr, stat);
 		}
 	}
+	if (err == -ENOENT) {
+		struct dentry *entry;
+
+		entry = d_obtain_alias(inode);

Why d_obtain_alias() instead of d_find_any_alias()?

And what if you find the wrong alias? ie an inode with two links? Or does fuse not support hardlinks?

#2 lore raw

we should us d_find_any_alias() rather than d_obtain_alias(), it's my mistake.

Fuse is support hardlinks, if an inode with two links, we may found wrong alias, we may need invalidate all dentry, because of the file is not exist anymore.
But in other kernel code, I didn't see any handling for this situation. I can't figure out why.

Thanks.

-----邮件原件-----
发件人: Matthew Wilcox <[email protected]>
发送时间: 2021年5月14日 10:27
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected]
主题: Re: [PATCH] fuse: fix inconsistent status between faccess and mkdir

Review static int fuse_do_getattr(struct inode *inode,

Quoted 2 lines · Fengnan Chang

+++ b/fs/fuse/dir.c

(quoted diff) +0 -0
@@ -1065,6 +1065,14 @@ static int fuse_do_getattr(struct inode *inode,

struct kstat *stat,

fs/fuse/dir.c static int fuse_do_getattr(struct inode *inode, struct kstat *stat, · line 1071

Quoted 7 lines
fs/fuse/dir.c +4 -0
 				fuse_fillattr(inode, &outarg.attr, stat);
 		}
 	}
+	if (err == -ENOENT) {
+		struct dentry *entry;
+
+		entry = d_obtain_alias(inode);

Why d_obtain_alias() instead of d_find_any_alias()?

And what if you find the wrong alias? ie an inode with two links? Or does fuse not support hardlinks?