]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
9p: Add mount option for negative dentry cache retention
authorRemi Pommarel <repk@triplefau.lt>
Thu, 21 May 2026 09:40:30 +0000 (11:40 +0200)
committerDominique Martinet <asmadeus@codewreck.org>
Sun, 21 Jun 2026 05:22:56 +0000 (05:22 +0000)
Introduce a new mount option, negtimeout, for v9fs that allows users
to specify how long negative dentries are retained in the cache. The
retention time can be set in milliseconds (e.g. negtimeout=10000 for
a 10secs retention time) or a negative value (e.g. negtimeout=-1) to
keep negative entries until the buffer cache management removes them.

For consistency reasons, this option should only be used in exclusive
or read-only mount scenarios, aligning with the cache=loose usage.

Signed-off-by: Remi Pommarel <repk@triplefau.lt>
Message-ID: <b2d66500aa5a2f6540347c4aa46a4be10dd01bc6.1779355927.git.repk@triplefau.lt>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
Documentation/filesystems/9p.rst
fs/9p/v9fs.c
fs/9p/v9fs.h

index 65809a1dad21869895fd08765fbd2eae60e5e2d6..3f65db648db06a1b3dc36f8d9066df2b1234e7b8 100644 (file)
@@ -235,6 +235,11 @@ Options
   cachetag     cache tag to use the specified persistent cache.
                cache tags for existing cache sessions can be listed at
                /sys/fs/9p/caches. (applies only to cache=fscache)
+
+  negtimeout    the duration (in milliseconds) that negative dentries (paths
+                that do not actually exist) are retained in the cache. If
+                set to a negative value, those entries are kept indefinitely
+                until evicted by the buffer cache management system
   ============= ===============================================================
 
 Behavior
index be83744b75b27dc2c5141fb370ce1a9094403938..3e758b66fefaeb9cf063d2a62485ec0e42b1eb22 100644 (file)
@@ -39,7 +39,7 @@ enum {
         * source if we rejected it as EINVAL */
        Opt_source,
        /* Options that take integer arguments */
-       Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid,
+       Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid, Opt_negtimeout,
        /* String options */
        Opt_uname, Opt_remotename, Opt_cache, Opt_cachetag,
        /* Options that take no arguments */
@@ -93,6 +93,7 @@ const struct fs_parameter_spec v9fs_param_spec[] = {
        fsparam_string  ("access",      Opt_access),
        fsparam_flag    ("posixacl",    Opt_posixacl),
        fsparam_u32     ("locktimeout", Opt_locktimeout),
+       fsparam_s32     ("negtimeout",  Opt_negtimeout),
 
        /* client options */
        fsparam_u32     ("msize",       Opt_msize),
@@ -159,6 +160,9 @@ int v9fs_show_options(struct seq_file *m, struct dentry *root)
                           from_kgid_munged(&init_user_ns, v9ses->dfltgid));
        if (v9ses->afid != ~0)
                seq_printf(m, ",afid=%u", v9ses->afid);
+       if (v9ses->flags & V9FS_NDENTRY_TIMEOUT_SET)
+               seq_printf(m, ",negtimeout=%d",
+                          (int)v9ses->ndentry_timeout_ms);
        if (strcmp(v9ses->uname, V9FS_DEFUSER) != 0)
                seq_printf(m, ",uname=%s", v9ses->uname);
        if (strcmp(v9ses->aname, V9FS_DEFANAME) != 0)
@@ -337,6 +341,16 @@ int v9fs_parse_param(struct fs_context *fc, struct fs_parameter *param)
                session_opts->session_lock_timeout = (long)result.uint_32 * HZ;
                break;
 
+       case Opt_negtimeout:
+               session_opts->flags |= V9FS_NDENTRY_TIMEOUT_SET;
+               if (result.int_32 < 0) {
+                       session_opts->ndentry_timeout_ms =
+                               NDENTRY_TIMEOUT_NEVER;
+               } else {
+                       session_opts->ndentry_timeout_ms = result.int_32;
+               }
+               break;
+
        /* Options for client */
        case Opt_msize:
                if (result.uint_32 < 4096) {
index e630c5111d749fe03b2703d211136dc139e5300c..a462bcbfc7da488e7bd6d864650307663ae0e92f 100644 (file)
@@ -24,6 +24,8 @@
  * @V9FS_ACCESS_ANY: use a single attach for all users
  * @V9FS_ACCESS_MASK: bit mask of different ACCESS options
  * @V9FS_POSIX_ACL: POSIX ACLs are enforced
+ * @V9FS_NDENTRY_TIMEOUT_SET: Has negative dentry timeout retention time been
+ *                            overridden by negtimeout mount option
  *
  * Session flags reflect options selected by users at mount time
  */
 #define V9FS_ACL_MASK V9FS_POSIX_ACL
 
 enum p9_session_flags {
-       V9FS_PROTO_2000U    = 0x01,
-       V9FS_PROTO_2000L    = 0x02,
-       V9FS_ACCESS_SINGLE  = 0x04,
-       V9FS_ACCESS_USER    = 0x08,
-       V9FS_ACCESS_CLIENT  = 0x10,
-       V9FS_POSIX_ACL      = 0x20,
-       V9FS_NO_XATTR       = 0x40,
-       V9FS_IGNORE_QV      = 0x80, /* ignore qid.version for cache hints */
-       V9FS_DIRECT_IO      = 0x100,
-       V9FS_SYNC           = 0x200
+       V9FS_PROTO_2000U         = 0x01,
+       V9FS_PROTO_2000L         = 0x02,
+       V9FS_ACCESS_SINGLE       = 0x04,
+       V9FS_ACCESS_USER         = 0x08,
+       V9FS_ACCESS_CLIENT       = 0x10,
+       V9FS_POSIX_ACL           = 0x20,
+       V9FS_NO_XATTR            = 0x40,
+       V9FS_IGNORE_QV           = 0x80, /* ignore qid.version for cache hints */
+       V9FS_DIRECT_IO           = 0x100,
+       V9FS_SYNC                = 0x200,
+       V9FS_NDENTRY_TIMEOUT_SET = 0x400,
 };
 
 /**