Skip to content

Conversation

@yangliping
Copy link
Contributor

Add InodeNotify call in Open method to force kernel cache invalidation when files are opened. This ensures that clients get fresh inode attribute information instead of relying on potentially stale cached data.

The change calls fsserv.InodeNotify() with the opened file's inode ID to notify the kernel to invalidate its cached attribute information. This improves consistency across multiple clients accessing the same files.

Resolves: #6323

Add InodeNotify call in Open method to force kernel cache invalidation
when files are opened. This ensures that clients get fresh inode
attribute information instead of relying on potentially stale cached data.

The change calls fsserv.InodeNotify() with the opened file's inode ID
to notify the kernel to invalidate its cached attribute information.
This improves consistency across multiple clients accessing the same files.

Resolves: juicedata#6323
@CLAassistant
Copy link

CLAassistant commented Aug 25, 2025

CLA assistant check
All committers have signed the CLA.

@polyrabbit
Copy link
Contributor

Be careful to not introduce a deadlock when calling InodeNotify.

@yangliping
Copy link
Contributor Author

1. Frequency

InodeNotify is invoked at most once per file—right when it is opened.

2. Safety

It never endangers the JuiceFS daemon:

  • Non-blocking, one-way invalidation signal.
  • Executed after the file is already opened.
  • Failure does not roll back the open.

3. Deadlock Risk

  • Pure user-space → kernel notification; no two-way locking.
  • go-fuse’s InodeNotify is thread-safe and deadlock-free.
  • Called with no internal JuiceFS locks held.
  • The kernel handles invalidation under its own concurrency rules.

pkg/fuse/fuse.go Outdated
} else if entry.Attr.KeepCache {
out.OpenFlags |= fuse.FOPEN_KEEP_CACHE
}
fsserv.InodeNotify(uint64(in.NodeId), -1, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OpenFlags is used to tell kernel to invalidate data cache.

The returned attribute of Open should overwrite stale attr in kernel, so InodeNotify is not needed, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, certain OpenFlags can affect how the kernel handles file caching, but there is no specific flag dedicated to 'invalidating the cache'.

Copy link
Contributor

@jiefenghuang jiefenghuang Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe change to this, only invalidate cache when mtime changed. @yangliping

else if entry.Attr.KeepCache {
	out.OpenFlags |= fuse.FOPEN_KEEP_CACHE
} else  {
	fsserv.InodeNotify(uint64(in.NodeId), -1, 0)
}

Move the fsserv.InodeNotifycall inside the else branch to prevent unnecessary notifications.
@davies davies merged commit d05e58a into juicedata:main Sep 3, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stale attribute cache breaks Close-to-Open consistency

5 participants