mirror of
https://git.openafs.org/openafs.git
synced 2025-01-31 05:27:44 +00:00
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 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> (cherry picked from commit d460b616ebad763f7e480e194b2bffc28df99721) Change-Id: I184046469c396b0421752d91c47477ebe8eaed13 Reviewed-on: https://gerrit.openafs.org/15515 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Tested-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Mark Vitale <mvitale@sinenomine.net> Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
This commit is contained in:
parent
a50282c70f
commit
898098e01e
@ -49,6 +49,10 @@ typedef struct path afs_linux_path_t;
|
||||
# define d_alias d_u.d_alias
|
||||
#endif
|
||||
|
||||
#if defined(STRUCT_DENTRY_HAS_D_U_D_CHILD)
|
||||
# define d_child d_u.d_child
|
||||
#endif
|
||||
|
||||
#if defined(STRUCT_FILE_HAS_F_PATH)
|
||||
# if !defined(f_dentry)
|
||||
# define f_dentry f_path.dentry
|
||||
|
@ -272,3 +272,56 @@ osi_ShouldDeferRemunlink(struct vcache *avc)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Invalidate Linux-specific cached data for the given vcache. This doesn't
|
||||
* handle anything with the OpenAFS disk cache or stat cache, etc; those things
|
||||
* are handled by afs_ResetVCache().
|
||||
*
|
||||
* The Linux-specific stuff we clear here is dcache entries. This means
|
||||
* clearing d_time in all dentry's for the vcache, and all immediate children
|
||||
* (for directories). We don't call d_invalidate() or any similar functions
|
||||
* here; let afs_linux_dentry_revalidate() figure out what to do with the
|
||||
* invalid dentry's whenever they are accessed.
|
||||
*
|
||||
* @pre AFS_GLOCK held
|
||||
*/
|
||||
void
|
||||
osi_ResetVCache(struct vcache *avc)
|
||||
{
|
||||
struct dentry *dp;
|
||||
struct inode *ip = AFSTOV(avc);
|
||||
#if defined(D_ALIAS_IS_HLIST) && !defined(HLIST_ITERATOR_NO_NODE)
|
||||
struct hlist_node *node;
|
||||
#endif
|
||||
|
||||
AFS_GUNLOCK();
|
||||
|
||||
afs_d_alias_lock(ip);
|
||||
|
||||
afs_d_alias_foreach(dp, ip, node) {
|
||||
spin_lock(&dp->d_lock);
|
||||
|
||||
/* Invalidate the dentry for the given vcache. */
|
||||
dp->d_time = 0;
|
||||
|
||||
if (S_ISDIR(ip->i_mode)) {
|
||||
/*
|
||||
* If the vcache is a dir, also invalidate all of its children.
|
||||
* Note that we can lock child->d_lock while dp->d_lock is held,
|
||||
* because 'dp' is an ancestor of 'child'.
|
||||
*/
|
||||
struct dentry *child;
|
||||
list_for_each_entry(child, &dp->d_subdirs, d_child) {
|
||||
spin_lock(&child->d_lock);
|
||||
child->d_time = 0;
|
||||
spin_unlock(&child->d_lock);
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock(&dp->d_lock);
|
||||
}
|
||||
afs_d_alias_unlock(ip);
|
||||
|
||||
AFS_GLOCK();
|
||||
}
|
||||
|
@ -149,6 +149,12 @@ extern void osi_PrePopulateVCache(struct vcache *);
|
||||
extern void osi_PostPopulateVCache(struct vcache *);
|
||||
extern void osi_AttachVnode(struct vcache *, int seq);
|
||||
|
||||
#ifdef AFS_LINUX_ENV
|
||||
extern void osi_ResetVCache(struct vcache *avc);
|
||||
#else
|
||||
# define osi_ResetVCache(avc) do { } while (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Increment the refcount on the given vcache.
|
||||
*
|
||||
|
@ -2561,6 +2561,8 @@ afs_ResetVCache(struct vcache *avc, afs_ucred_t *acred, afs_int32 skipdnlc)
|
||||
afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
|
||||
avc->linkData = NULL;
|
||||
}
|
||||
|
||||
osi_ResetVCache(avc);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -14,6 +14,9 @@ AC_CHECK_LINUX_STRUCT([backing_dev_info], [name],
|
||||
AC_CHECK_LINUX_STRUCT([cred], [session_keyring], [cred.h])
|
||||
AC_CHECK_LINUX_STRUCT([ctl_table], [ctl_name], [sysctl.h])
|
||||
AC_CHECK_LINUX_STRUCT([dentry], [d_u.d_alias], [dcache.h])
|
||||
dnl linux 2.6.16 moved dentry->d_child to dentry->d_u.d_child
|
||||
dnl linux 3.19 moved it back to dentry->d_child
|
||||
AC_CHECK_LINUX_STRUCT([dentry], [d_u.d_child], [dcache.h])
|
||||
AC_CHECK_LINUX_STRUCT([dentry_operations], [d_automount], [dcache.h])
|
||||
AC_CHECK_LINUX_STRUCT([group_info], [gid], [cred.h])
|
||||
AC_CHECK_LINUX_STRUCT([inode], [i_alloc_sem], [fs.h])
|
||||
|
Loading…
x
Reference in New Issue
Block a user