LINUX: Make 'fs flush*' invalidate dentry 91/15391/5
authorAndrew Deason <adeason@sinenomine.net>
Fri, 7 Apr 2023 21:09:30 +0000 (16:09 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 12 May 2023 21:36:15 +0000 (17:36 -0400)
commitd460b616ebad763f7e480e194b2bffc28df99721
tree34949f3fdc0801715f699d0e2d588f95c7864e50
parent2b32b130f534068251ce9fd1b621de6e480d56d7
LINUX: Make 'fs flush*' invalidate dentry

Our 'fs flush' and related commands (flushall, flushvolume) clear the
relevant entries in the OpenAFS stat cache and data cache, which can
fix problems if the cache ever becomes incorrect for any reason. (This
can happen after bugs, repairing corrupted volumes, disaster recovery
scenarios, and similar edge cases.)

However, on Linux, these commands don't affect the VFS dentry cache.
If someone needs to use an 'fs flush' command to fix a problem, this
will fix the OpenAFS cache, but the Linux dcache can still be wrong.
The only way to manually flush dcache entries is to use the global
'drop_caches' mechanism, which is a very heavweight operation, only
accessible to root.

For example:

    $ ls -l
    ls: cannot access foo.1: No such file or directory
    total 2
    drwxrwxr-x. 2 bin adeason 2048 Apr  6 14:20 dir
    -?????????? ? ?   ?          ?            ? foo.1
    $ fs flush .
    $ ls -l
    ls: cannot access foo.1: No such file or directory
    total 2
    drwxrwxr-x. 2 bin adeason 2048 Apr  6 14:20 dir
    -?????????? ? ?   ?          ?            ? foo.1
    $ sudo sysctl -q -w vm.drop_caches=3
    $ ls -l
    total 3
    drwxrwxr-x. 2 bin adeason 2048 Apr  6 14:20 dir
    -rw-rw-r--. 1 bin adeason   29 Sep 22  2022 foo.1

To make the 'fs flush' commands be effective in more situations,
change afs_ResetVCache() to also invalidate the dcache entries
associated with each vcache we reset. To make things simpler and
reduce locking complexity, do this by setting d_time to 0, and don't
directly run dcache-managing functions like d_invalidate or d_drop,
etc.

The above example now becomes:

    $ ls -l
    ls: cannot access foo.1: No such file or directory
    total 2
    drwxrwxr-x. 2 bin adeason 2048 Apr  6 14:20 dir
    -?????????? ? ?   ?          ?            ? foo.1
    $ fs flush .
    $ ls -l
    total 3
    drwxrwxr-x. 2 bin adeason 2048 Apr  6 14:20 dir
    -rw-rw-r--. 1 bin adeason   29 Sep 22  2022 foo.1

Change-Id: Ic95ef6137f5b671baf68a4890ef1562f029af794
Reviewed-on: https://gerrit.openafs.org/15391
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
src/afs/LINUX/osi_compat.h
src/afs/LINUX/osi_vcache.c
src/afs/afs_osi.h
src/afs/afs_vcache.c
src/cf/linux-kernel-struct.m4