00e543
From da57354dc8593d37eff59bc7836ee4e460a2659a Mon Sep 17 00:00:00 2001
00e543
From: Nikolaus Rath <Nikolaus@rath.org>
00e543
Date: Sat, 6 Apr 2019 18:34:57 +0100
00e543
Subject: [PATCH 4/4] Add support for in-kernel readdir caching.
00e543
00e543
Fixes: #394.
00e543
(cherry picked from commit 1552b467fcd7751360299c5139382d78538e12b3)
00e543
Signed-off-by: Pavel Reichl <preichl@redhat.com>
00e543
---
00e543
 include/fuse_common.h | 18 +++++++++++++-----
00e543
 lib/fuse_lowlevel.c   |  2 ++
00e543
 2 files changed, 15 insertions(+), 5 deletions(-)
00e543
00e543
diff --git a/include/fuse_common.h b/include/fuse_common.h
00e543
index a5a0ea5..a28ffa5 100644
00e543
--- a/include/fuse_common.h
00e543
+++ b/include/fuse_common.h
00e543
@@ -45,9 +45,11 @@ struct fuse_file_info {
00e543
 	/** Can be filled in by open, to use direct I/O on this file. */
00e543
 	unsigned int direct_io : 1;
00e543
 
00e543
-	/** Can be filled in by open, to indicate that currently
00e543
-	    cached file data (that the filesystem provided the last
00e543
-	    time the file was open) need not be invalidated. */
00e543
+	/** Can be filled in by open. It signals the kernel that any
00e543
+	    currently cached file data (ie., data that the filesystem
00e543
+	    provided the last time the file was open) need not be
00e543
+	    invalidated. Has no effect when set in other contexts (in
00e543
+	    particular it does nothing when set by opendir()). */
00e543
 	unsigned int keep_cache : 1;
00e543
 
00e543
 	/** Indicates a flush operation.  Set in flush operation, also
00e543
@@ -64,8 +66,14 @@ struct fuse_file_info {
00e543
 	   May only be set in ->release(). */
00e543
 	unsigned int flock_release : 1;
00e543
 
00e543
-	/** Padding.  Do not use*/
00e543
-	unsigned int padding : 27;
00e543
+	/** Can be filled in by opendir. It signals the kernel to
00e543
+	    enable caching of entries returned by readdir().  Has no
00e543
+	    effect when set in other contexts (in particular it does
00e543
+	    nothing when set by open()). */
00e543
+	unsigned int cache_readdir : 1;
00e543
+
00e543
+	/** Padding.  Reserved for future use*/
00e543
+	unsigned int padding : 26;
00e543
 
00e543
 	/** File handle.  May be filled in by filesystem in open().
00e543
 	    Available in all other file operations */
00e543
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
00e543
index 43f785f..6379e09 100644
00e543
--- a/lib/fuse_lowlevel.c
00e543
+++ b/lib/fuse_lowlevel.c
00e543
@@ -392,6 +392,8 @@ static void fill_open(struct fuse_open_out *arg,
00e543
 		arg->open_flags |= FOPEN_DIRECT_IO;
00e543
 	if (f->keep_cache)
00e543
 		arg->open_flags |= FOPEN_KEEP_CACHE;
00e543
+	if (f->cache_readdir)
00e543
+		arg->open_flags |= FOPEN_CACHE_DIR;
00e543
 	if (f->nonseekable)
00e543
 		arg->open_flags |= FOPEN_NONSEEKABLE;
00e543
 }
00e543
-- 
00e543
2.36.1
00e543