Invalidate FUSE VFS dentry cache
To improve filesystem performance we can reduce unnecessary
requests to the FUSE daemon by enabling VFS caching of dentries
after a FUSE_LOOKUP request.
To enable correctly, we should ensure that the lower filesystem
dentries are not modified outside of the FUSE driver. Unfortunately,
we already do this when handling IO requests over binder using the
ContentResolver interface.
To fix, we should invalidate any FUSE dentries in the VFS cache so that
subsequent lookups for those files do not return incorrectly cached
values from the VFS.
This change just adds support for invalidating FUSE VFS cache
dentries, subsequent cl will call it when required. Note that it
should never be called in the execution path of a related filesytem
operation. See fuse_lowlevel.h for more details. Will ensure that this
is never called in the FUSE execution path in a follow up
Test: atest FuseDaemonHostTest#testVfsCacheConsistency
Bug: 145741152
Change-Id: I54e67f63a29c82a392916fb28d1a7f8f894c685b
diff --git a/jni/com_android_providers_media_FuseDaemon.cpp b/jni/com_android_providers_media_FuseDaemon.cpp
index caf00b2..87861ca 100644
--- a/jni/com_android_providers_media_FuseDaemon.cpp
+++ b/jni/com_android_providers_media_FuseDaemon.cpp
@@ -73,6 +73,22 @@
return JNI_FALSE;
}
+void com_android_providers_media_FuseDaemon_invalidate_fuse_dentry_cache(JNIEnv* env, jobject self,
+ jlong java_daemon,
+ jstring java_path) {
+ fuse::FuseDaemon* const daemon = reinterpret_cast<fuse::FuseDaemon*>(java_daemon);
+ if (daemon) {
+ ScopedUtfChars utf_chars_path(env, java_path);
+ if (!utf_chars_path.c_str()) {
+ // TODO(b/145741152): Throw exception
+ return;
+ }
+
+ daemon->InvalidateFuseDentryCache(utf_chars_path.c_str());
+ }
+ // TODO(b/145741152): Throw exception
+}
+
const JNINativeMethod methods[] = {
{"native_new", "(Lcom/android/providers/media/MediaProvider;)J",
reinterpret_cast<void*>(com_android_providers_media_FuseDaemon_new)},
@@ -81,8 +97,10 @@
{"native_delete", "(J)V",
reinterpret_cast<void*>(com_android_providers_media_FuseDaemon_delete)},
{"native_should_open_with_fuse", "(JLjava/lang/String;ZI)Z",
- reinterpret_cast<void*>(com_android_providers_media_FuseDaemon_should_open_with_fuse)}};
-
+ reinterpret_cast<void*>(com_android_providers_media_FuseDaemon_should_open_with_fuse)},
+ {"native_invalidate_fuse_dentry_cache", "(JLjava/lang/String;)V",
+ reinterpret_cast<void*>(
+ com_android_providers_media_FuseDaemon_invalidate_fuse_dentry_cache)}};
} // namespace
void register_android_providers_media_FuseDaemon(JNIEnv* env) {