diff options
author | Mateusz Guzik <mjg@FreeBSD.org> | 2021-01-01 07:06:12 +0000 |
---|---|---|
committer | Mateusz Guzik <mjg@FreeBSD.org> | 2021-01-06 07:28:06 +0000 |
commit | 33f3e81df531d62a53390de20812d4e94720e1d3 (patch) | |
tree | 72b585160b94d53b9b42206d76210c30e5907af5 | |
parent | dbbbc07cc3e5e6843ca95550ca2f50e329e93a9e (diff) | |
download | src-33f3e81df531d62a53390de20812d4e94720e1d3.tar.gz src-33f3e81df531d62a53390de20812d4e94720e1d3.zip |
-rw-r--r-- | sys/kern/vfs_cache.c | 51 | ||||
-rw-r--r-- | sys/security/mac/mac_framework.c | 3 | ||||
-rw-r--r-- | sys/sys/vnode.h | 1 |
3 files changed, 43 insertions, 12 deletions
diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index ad661339b492..40298cd9fbdc 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -3571,12 +3571,45 @@ DB_SHOW_COMMAND(vpath, db_show_vpath) #endif -static bool __read_frequently cache_fast_lookup = true; -SYSCTL_BOOL(_vfs, OID_AUTO, cache_fast_lookup, CTLFLAG_RW, - &cache_fast_lookup, 0, ""); +static int cache_fast_lookup = 1; +static char __read_frequently cache_fast_lookup_enabled = true; #define CACHE_FPL_FAILED -2020 +void +cache_fast_lookup_enabled_recalc(void) +{ + int lookup_flag; + int mac_on; + +#ifdef MAC + mac_on = mac_vnode_check_lookup_enabled(); +#else + mac_on = 0; +#endif + + lookup_flag = atomic_load_int(&cache_fast_lookup); + if (lookup_flag && !mac_on) { + atomic_store_char(&cache_fast_lookup_enabled, true); + } else { + atomic_store_char(&cache_fast_lookup_enabled, false); + } +} + +static int +syscal_vfs_cache_fast_lookup(SYSCTL_HANDLER_ARGS) +{ + int error, old; + + old = atomic_load_int(&cache_fast_lookup); + error = sysctl_handle_int(oidp, arg1, arg2, req); + if (error == 0 && req->newptr && old != atomic_load_int(&cache_fast_lookup)) + cache_fast_lookup_enabled_recalc(); + return (error); +} +SYSCTL_PROC(_vfs, OID_AUTO, cache_fast_lookup, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_MPSAFE, + &cache_fast_lookup, 0, syscal_vfs_cache_fast_lookup, "IU", ""); + /* * Components of nameidata (or objects it can point to) which may * need restoring in case fast path lookup fails. @@ -3854,16 +3887,10 @@ cache_can_fplookup(struct cache_fpl *fpl) cnp = fpl->cnp; td = cnp->cn_thread; - if (!cache_fast_lookup) { - cache_fpl_aborted_early(fpl); - return (false); - } -#ifdef MAC - if (mac_vnode_check_lookup_enabled()) { + if (!atomic_load_char(&cache_fast_lookup_enabled)) { cache_fpl_aborted_early(fpl); return (false); } -#endif if ((cnp->cn_flags & ~CACHE_FPL_SUPPORTED_CN_FLAGS) != 0) { cache_fpl_aborted_early(fpl); return (false); @@ -5205,9 +5232,9 @@ cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status, } MPASS(cnp->cn_nameptr == cnp->cn_pnbuf); - if (!cache_can_fplookup(&fpl)) { - SDT_PROBE3(vfs, fplookup, lookup, done, ndp, fpl.line, fpl.status); + if (__predict_false(!cache_can_fplookup(&fpl))) { *status = fpl.status; + SDT_PROBE3(vfs, fplookup, lookup, done, ndp, fpl.line, fpl.status); return (EOPNOTSUPP); } diff --git a/sys/security/mac/mac_framework.c b/sys/security/mac/mac_framework.c index 3ec932147637..c1d52eff383e 100644 --- a/sys/security/mac/mac_framework.c +++ b/sys/security/mac/mac_framework.c @@ -82,6 +82,7 @@ __FBSDID("$FreeBSD$"); #include <sys/sdt.h> #include <sys/sx.h> #include <sys/sysctl.h> +#include <sys/vnode.h> #include <security/mac/mac_framework.h> #include <security/mac/mac_internal.h> @@ -399,6 +400,8 @@ mac_policy_update(void) mac_labeled |= mac_policy_getlabeled(mpc); mac_policy_count++; } + + cache_fast_lookup_enabled_recalc(); } /* diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 9be22f02e8d4..cb71d80c244f 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -657,6 +657,7 @@ cache_validate(struct vnode *dvp, struct vnode *vp, struct componentname *cnp) { } #endif +void cache_fast_lookup_enabled_recalc(void); int change_dir(struct vnode *vp, struct thread *td); void cvtstat(struct stat *st, struct ostat *ost); void freebsd11_cvtnstat(struct stat *sb, struct nstat *nsb); |