ANDROID: sdcardfs: Add option to drop unused dentries
authorDaniel Rosenberg <drosen@google.com>
Fri, 6 Jul 2018 23:24:27 +0000 (16:24 -0700)
committerDanny Wood <danwood76@gmail.com>
Fri, 8 Nov 2019 12:04:11 +0000 (12:04 +0000)
This adds the nocache mount option, which will cause sdcardfs to always
drop dentries that are not in use, preventing cached entries from
holding on to lower dentries, which could  cause strange behavior when
bypassing the sdcardfs layer and directly changing the lower fs.

Change-Id: I70268584a20b989ae8cfdd278a2e4fa1605217fb
Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Paul Keith <javelinanddart@gmail.com>
fs/sdcardfs/dentry.c
fs/sdcardfs/main.c
fs/sdcardfs/sdcardfs.h
fs/sdcardfs/super.c

index 4896ba1c0ceb3b92f61b4f7e4c31dce7b9dfea05..c8a68289d7b60cd825519d0016bced44c35a3a2c 100644 (file)
@@ -123,6 +123,12 @@ out:
        return err;
 }
 
+/* 1 = delete, 0 = cache */
+static int sdcardfs_d_delete(const struct dentry *d)
+{
+       return SDCARDFS_SB(d->d_sb)->options.nocache ? 1 : 0;
+}
+
 static void sdcardfs_d_release(struct dentry *dentry)
 {
        if (!dentry || !dentry->d_fsdata)
@@ -181,6 +187,7 @@ static void sdcardfs_canonical_path(const struct path *path, struct path *actual
 
 const struct dentry_operations sdcardfs_ci_dops = {
        .d_revalidate   = sdcardfs_d_revalidate,
+       .d_delete       = sdcardfs_d_delete,
        .d_release      = sdcardfs_d_release,
        .d_hash = sdcardfs_hash_ci,
        .d_compare      = sdcardfs_cmp_ci,
index b60f5edfa834d288733669d46d88f0c0c91dd071..474f12041211788a80bb47d66a2895a8a9c6e124 100644 (file)
@@ -34,6 +34,7 @@ enum {
        Opt_reserved_mb,
        Opt_gid_derivation,
        Opt_default_normal,
+       Opt_nocache,
        Opt_err,
 };
 
@@ -48,6 +49,7 @@ static const match_table_t sdcardfs_tokens = {
        {Opt_gid_derivation, "derive_gid"},
        {Opt_default_normal, "default_normal"},
        {Opt_reserved_mb, "reserved_mb=%u"},
+       {Opt_nocache, "nocache"},
        {Opt_err, NULL}
 };
 
@@ -71,6 +73,7 @@ static int parse_options(struct super_block *sb, char *options, int silent,
        /* by default, gid derivation is off */
        opts->gid_derivation = false;
        opts->default_normal = false;
+       opts->nocache = false;
 
        *debug = 0;
 
@@ -128,6 +131,9 @@ static int parse_options(struct super_block *sb, char *options, int silent,
                case Opt_default_normal:
                        opts->default_normal = true;
                        break;
+               case Opt_nocache:
+                       opts->nocache = true;
+                       break;
                /* unknown option */
                default:
                        if (!silent)
index 6e29c89e1d8eebdc783b2b43110e1680dfac1aa3..b05cc248f2f2924b0e729bb3187836dfbe3b14e9 100644 (file)
@@ -197,6 +197,7 @@ struct sdcardfs_mount_options {
        bool gid_derivation;
        bool default_normal;
        unsigned int reserved_mb;
+       bool nocache;
 };
 
 struct sdcardfs_vfsmount_options {
index c9447dfdcdfb6836f9861a6f2cbba4450d661f4a..16957cf5758bf269cd02bb02c072497e527dffea 100644 (file)
@@ -311,6 +311,8 @@ static int sdcardfs_show_options(struct vfsmount *mnt, struct seq_file *m,
                seq_puts(m, ",default_normal");
        if (opts->reserved_mb != 0)
                seq_printf(m, ",reserved=%uMB", opts->reserved_mb);
+       if (opts->nocache)
+               seq_printf(m, ",nocache");
 
        return 0;
 };