Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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