2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Cache operations for Coda.
|
|
|
|
* For Linux 2.1: (C) 1997 Carnegie Mellon University
|
|
|
|
* For Linux 2.3: (C) 2000 Carnegie Mellon University
|
|
|
|
*
|
|
|
|
* Carnegie Mellon encourages users of this code to contribute improvements
|
|
|
|
* to the Coda project http://www.coda.cs.cmu.edu/ <coda@cs.cmu.edu>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/errno.h>
|
2014-08-08 21:20:33 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/list.h>
|
Detach sched.h from mm.h
First thing mm.h does is including sched.h solely for can_do_mlock() inline
function which has "current" dereference inside. By dealing with can_do_mlock()
mm.h can be detached from sched.h which is good. See below, why.
This patch
a) removes unconditional inclusion of sched.h from mm.h
b) makes can_do_mlock() normal function in mm/mlock.c
c) exports can_do_mlock() to not break compilation
d) adds sched.h inclusions back to files that were getting it indirectly.
e) adds less bloated headers to some files (asm/signal.h, jiffies.h) that were
getting them indirectly
Net result is:
a) mm.h users would get less code to open, read, preprocess, parse, ... if
they don't need sched.h
b) sched.h stops being dependency for significant number of files:
on x86_64 allmodconfig touching sched.h results in recompile of 4083 files,
after patch it's only 3744 (-8.3%).
Cross-compile tested on
all arm defconfigs, all mips defconfigs, all powerpc defconfigs,
alpha alpha-up
arm
i386 i386-up i386-defconfig i386-allnoconfig
ia64 ia64-up
m68k
mips
parisc parisc-up
powerpc powerpc-up
s390 s390-up
sparc sparc-up
sparc64 sparc64-up
um-x86_64
x86_64 x86_64-up x86_64-defconfig x86_64-allnoconfig
as well as my two usual configs.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-20 21:22:52 +00:00
|
|
|
#include <linux/sched.h>
|
2010-10-25 06:03:44 +00:00
|
|
|
#include <linux/spinlock.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <linux/coda.h>
|
|
|
|
#include <linux/coda_psdev.h>
|
2011-01-12 21:36:09 +00:00
|
|
|
#include "coda_linux.h"
|
|
|
|
#include "coda_cache.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static atomic_t permission_epoch = ATOMIC_INIT(0);
|
|
|
|
|
|
|
|
/* replace or extend an acl cache hit */
|
|
|
|
void coda_cache_enter(struct inode *inode, int mask)
|
|
|
|
{
|
|
|
|
struct coda_inode_info *cii = ITOC(inode);
|
|
|
|
|
2010-10-25 06:03:44 +00:00
|
|
|
spin_lock(&cii->c_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
cii->c_cached_epoch = atomic_read(&permission_epoch);
|
2013-01-31 03:36:06 +00:00
|
|
|
if (!uid_eq(cii->c_uid, current_fsuid())) {
|
2008-11-13 23:38:48 +00:00
|
|
|
cii->c_uid = current_fsuid();
|
2005-04-16 22:20:36 +00:00
|
|
|
cii->c_cached_perm = mask;
|
|
|
|
} else
|
|
|
|
cii->c_cached_perm |= mask;
|
2010-10-25 06:03:44 +00:00
|
|
|
spin_unlock(&cii->c_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* remove cached acl from an inode */
|
|
|
|
void coda_cache_clear_inode(struct inode *inode)
|
|
|
|
{
|
|
|
|
struct coda_inode_info *cii = ITOC(inode);
|
2010-10-25 06:03:44 +00:00
|
|
|
spin_lock(&cii->c_lock);
|
2007-07-19 08:48:42 +00:00
|
|
|
cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
|
2010-10-25 06:03:44 +00:00
|
|
|
spin_unlock(&cii->c_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* remove all acl caches */
|
|
|
|
void coda_cache_clear_all(struct super_block *sb)
|
|
|
|
{
|
|
|
|
atomic_inc(&permission_epoch);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* check if the mask has been matched against the acl already */
|
|
|
|
int coda_cache_check(struct inode *inode, int mask)
|
|
|
|
{
|
|
|
|
struct coda_inode_info *cii = ITOC(inode);
|
2010-10-25 06:03:44 +00:00
|
|
|
int hit;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-10-25 06:03:44 +00:00
|
|
|
spin_lock(&cii->c_lock);
|
|
|
|
hit = (mask & cii->c_cached_perm) == mask &&
|
2013-01-31 03:36:06 +00:00
|
|
|
uid_eq(cii->c_uid, current_fsuid()) &&
|
2010-10-25 06:03:44 +00:00
|
|
|
cii->c_cached_epoch == atomic_read(&permission_epoch);
|
|
|
|
spin_unlock(&cii->c_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-10-25 06:03:44 +00:00
|
|
|
return hit;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Purging dentries and children */
|
|
|
|
/* The following routines drop dentries which are not
|
|
|
|
in use and flag dentries which are in use to be
|
|
|
|
zapped later.
|
|
|
|
|
|
|
|
The flags are detected by:
|
|
|
|
- coda_dentry_revalidate (for lookups) if the flag is C_PURGE
|
|
|
|
- coda_dentry_delete: to remove dentry from the cache when d_count
|
|
|
|
falls to zero
|
|
|
|
- an inode method coda_revalidate (for attributes) if the
|
|
|
|
flag is C_VATTR
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* this won't do any harm: just flag all children */
|
|
|
|
static void coda_flag_children(struct dentry *parent, int flag)
|
|
|
|
{
|
|
|
|
struct dentry *de;
|
|
|
|
|
2011-01-07 06:49:34 +00:00
|
|
|
spin_lock(&parent->d_lock);
|
2014-10-26 23:19:16 +00:00
|
|
|
list_for_each_entry(de, &parent->d_subdirs, d_child) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* don't know what to do with negative dentries */
|
2012-06-09 23:52:19 +00:00
|
|
|
if (de->d_inode )
|
|
|
|
coda_flag_inode(de->d_inode, flag);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2011-01-07 06:49:34 +00:00
|
|
|
spin_unlock(&parent->d_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void coda_flag_inode_children(struct inode *inode, int flag)
|
|
|
|
{
|
|
|
|
struct dentry *alias_de;
|
|
|
|
|
|
|
|
if ( !inode || !S_ISDIR(inode->i_mode))
|
|
|
|
return;
|
|
|
|
|
|
|
|
alias_de = d_find_alias(inode);
|
|
|
|
if (!alias_de)
|
|
|
|
return;
|
|
|
|
coda_flag_children(alias_de, flag);
|
|
|
|
shrink_dcache_parent(alias_de);
|
|
|
|
dput(alias_de);
|
|
|
|
}
|
|
|
|
|