1 // SPDX-License-Identifier: GPL-2.0 << 2 /* 1 /* 3 * Cache operations for Coda. 2 * Cache operations for Coda. 4 * For Linux 2.1: (C) 1997 Carnegie Mellon Uni 3 * For Linux 2.1: (C) 1997 Carnegie Mellon University 5 * For Linux 2.3: (C) 2000 Carnegie Mellon Uni 4 * For Linux 2.3: (C) 2000 Carnegie Mellon University 6 * 5 * 7 * Carnegie Mellon encourages users of this co 6 * Carnegie Mellon encourages users of this code to contribute improvements 8 * to the Coda project http://www.coda.cs.cmu. 7 * to the Coda project http://www.coda.cs.cmu.edu/ <coda@cs.cmu.edu>. 9 */ 8 */ 10 9 11 #include <linux/types.h> 10 #include <linux/types.h> 12 #include <linux/kernel.h> 11 #include <linux/kernel.h> 13 #include <linux/time.h> 12 #include <linux/time.h> 14 #include <linux/fs.h> 13 #include <linux/fs.h> 15 #include <linux/stat.h> 14 #include <linux/stat.h> 16 #include <linux/errno.h> 15 #include <linux/errno.h> 17 #include <linux/uaccess.h> !! 16 #include <asm/uaccess.h> 18 #include <linux/string.h> 17 #include <linux/string.h> 19 #include <linux/list.h> 18 #include <linux/list.h> 20 #include <linux/sched.h> 19 #include <linux/sched.h> 21 #include <linux/spinlock.h> << 22 20 23 #include <linux/coda.h> 21 #include <linux/coda.h> 24 #include "coda_psdev.h" !! 22 #include <linux/coda_linux.h> 25 #include "coda_linux.h" !! 23 #include <linux/coda_psdev.h> 26 #include "coda_cache.h" !! 24 #include <linux/coda_fs_i.h> >> 25 #include <linux/coda_cache.h> 27 26 28 static atomic_t permission_epoch = ATOMIC_INIT 27 static atomic_t permission_epoch = ATOMIC_INIT(0); 29 28 30 /* replace or extend an acl cache hit */ 29 /* replace or extend an acl cache hit */ 31 void coda_cache_enter(struct inode *inode, int 30 void coda_cache_enter(struct inode *inode, int mask) 32 { 31 { 33 struct coda_inode_info *cii = ITOC(ino 32 struct coda_inode_info *cii = ITOC(inode); 34 33 35 spin_lock(&cii->c_lock); << 36 cii->c_cached_epoch = atomic_read(&per 34 cii->c_cached_epoch = atomic_read(&permission_epoch); 37 if (!uid_eq(cii->c_uid, current_fsuid( !! 35 if (cii->c_uid != current_fsuid()) { 38 cii->c_uid = current_fsuid(); 36 cii->c_uid = current_fsuid(); 39 cii->c_cached_perm = mask; 37 cii->c_cached_perm = mask; 40 } else 38 } else 41 cii->c_cached_perm |= mask; 39 cii->c_cached_perm |= mask; 42 spin_unlock(&cii->c_lock); << 43 } 40 } 44 41 45 /* remove cached acl from an inode */ 42 /* remove cached acl from an inode */ 46 void coda_cache_clear_inode(struct inode *inod 43 void coda_cache_clear_inode(struct inode *inode) 47 { 44 { 48 struct coda_inode_info *cii = ITOC(ino 45 struct coda_inode_info *cii = ITOC(inode); 49 spin_lock(&cii->c_lock); << 50 cii->c_cached_epoch = atomic_read(&per 46 cii->c_cached_epoch = atomic_read(&permission_epoch) - 1; 51 spin_unlock(&cii->c_lock); << 52 } 47 } 53 48 54 /* remove all acl caches */ 49 /* remove all acl caches */ 55 void coda_cache_clear_all(struct super_block * 50 void coda_cache_clear_all(struct super_block *sb) 56 { 51 { 57 atomic_inc(&permission_epoch); 52 atomic_inc(&permission_epoch); 58 } 53 } 59 54 60 55 61 /* check if the mask has been matched against 56 /* check if the mask has been matched against the acl already */ 62 int coda_cache_check(struct inode *inode, int 57 int coda_cache_check(struct inode *inode, int mask) 63 { 58 { 64 struct coda_inode_info *cii = ITOC(ino 59 struct coda_inode_info *cii = ITOC(inode); 65 int hit; !! 60 int hit; 66 61 67 spin_lock(&cii->c_lock); !! 62 hit = (mask & cii->c_cached_perm) == mask && 68 hit = (mask & cii->c_cached_perm) == m !! 63 cii->c_uid == current_fsuid() && 69 uid_eq(cii->c_uid, current_fsuid() !! 64 cii->c_cached_epoch == atomic_read(&permission_epoch); 70 cii->c_cached_epoch == atomic_read << 71 spin_unlock(&cii->c_lock); << 72 65 73 return hit; !! 66 return hit; 74 } 67 } 75 68 76 69 77 /* Purging dentries and children */ 70 /* Purging dentries and children */ 78 /* The following routines drop dentries which 71 /* The following routines drop dentries which are not 79 in use and flag dentries which are in use t 72 in use and flag dentries which are in use to be 80 zapped later. 73 zapped later. 81 74 82 The flags are detected by: 75 The flags are detected by: 83 - coda_dentry_revalidate (for lookups) if t 76 - coda_dentry_revalidate (for lookups) if the flag is C_PURGE 84 - coda_dentry_delete: to remove dentry from 77 - coda_dentry_delete: to remove dentry from the cache when d_count 85 falls to zero 78 falls to zero 86 - an inode method coda_revalidate (for attr 79 - an inode method coda_revalidate (for attributes) if the 87 flag is C_VATTR 80 flag is C_VATTR 88 */ 81 */ 89 82 90 /* this won't do any harm: just flag all child 83 /* this won't do any harm: just flag all children */ 91 static void coda_flag_children(struct dentry * 84 static void coda_flag_children(struct dentry *parent, int flag) 92 { 85 { >> 86 struct list_head *child; 93 struct dentry *de; 87 struct dentry *de; 94 88 95 spin_lock(&parent->d_lock); !! 89 spin_lock(&dcache_lock); 96 hlist_for_each_entry(de, &parent->d_ch !! 90 list_for_each(child, &parent->d_subdirs) 97 struct inode *inode = d_inode_ !! 91 { >> 92 de = list_entry(child, struct dentry, d_u.d_child); 98 /* don't know what to do with 93 /* don't know what to do with negative dentries */ 99 if (inode) !! 94 if ( ! de->d_inode ) 100 coda_flag_inode(inode, !! 95 continue; >> 96 coda_flag_inode(de->d_inode, flag); 101 } 97 } 102 spin_unlock(&parent->d_lock); !! 98 spin_unlock(&dcache_lock); >> 99 return; 103 } 100 } 104 101 105 void coda_flag_inode_children(struct inode *in 102 void coda_flag_inode_children(struct inode *inode, int flag) 106 { 103 { 107 struct dentry *alias_de; 104 struct dentry *alias_de; 108 105 109 if ( !inode || !S_ISDIR(inode->i_mode) 106 if ( !inode || !S_ISDIR(inode->i_mode)) 110 return; 107 return; 111 108 112 alias_de = d_find_alias(inode); 109 alias_de = d_find_alias(inode); 113 if (!alias_de) 110 if (!alias_de) 114 return; 111 return; 115 coda_flag_children(alias_de, flag); 112 coda_flag_children(alias_de, flag); 116 shrink_dcache_parent(alias_de); 113 shrink_dcache_parent(alias_de); 117 dput(alias_de); 114 dput(alias_de); 118 } 115 } 119 116 120 117
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.